Case sensitive
This script reads a text file the matches it to pcname, then an if then statement is propesed to determine what comes next.
my text file is all caps, however when the netbios nbame is read it is sometimes lowercase. How would I edit my script to achieve non-case sensitive? I appreciate any help on this matter... Thank You!
Dim WSHShell, objWMIService, ColProcesses, oShell, sp, oEnv, WshNetwork, objIADsUser, objFSO, objFile, colMatches
Set oShell= CreateObject("Wscript.Shell")
Set oEnv = oShell.Environment("PROCESS")
'********************************************************************
'PC Name check for HTA
'********************************************************************
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objIADsUser = GetObject("WinNT://" & WshNetwork.UserDomain & "/" & WshNetwork.UserName & ",user")
pcname = WshNetwork.ComputerName
Const ForReading = 1
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = pcname
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("hta.txt", ForReading)
Do Until objFile.AtEndOfStream
strSearchString = objFile.ReadLine
Set colMatches = objRegEx.Execute(strSearchString)
If colMatches.Count = 1 Then
For Each strMatch in colMatches'
WScript.Quit [exitcode]
Next
End If
Loop
objFile.Close
my text file is all caps, however when the netbios nbame is read it is sometimes lowercase. How would I edit my script to achieve non-case sensitive? I appreciate any help on this matter... Thank You!
Dim WSHShell, objWMIService, ColProcesses, oShell, sp, oEnv, WshNetwork, objIADsUser, objFSO, objFile, colMatches
Set oShell= CreateObject("Wscript.Shell")
Set oEnv = oShell.Environment("PROCESS")
'********************************************************************
'PC Name check for HTA
'********************************************************************
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objIADsUser = GetObject("WinNT://" & WshNetwork.UserDomain & "/" & WshNetwork.UserName & ",user")
pcname = WshNetwork.ComputerName
Const ForReading = 1
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = pcname
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("hta.txt", ForReading)
Do Until objFile.AtEndOfStream
strSearchString = objFile.ReadLine
Set colMatches = objRegEx.Execute(strSearchString)
If colMatches.Count = 1 Then
For Each strMatch in colMatches'
WScript.Quit [exitcode]
Next
End If
Loop
objFile.Close
0 Comments
[ + ] Show comments
Answers (3)
Please log in to answer
Posted by:
captain_planet
14 years ago
Hmmm. Two things to note (unless I've got the wrong end of the stick here....).
1. To perform a case-insensitive regular expression, you should just use objRegEx.ignoreCase = true.
2. You say:
If colMatches.Count = 1 Then
For Each strMatch in
So in other words, if there's only one match, then loop through all the matches? Uh? That doesn't make sense. So, either:
a) Remove the 'For each....' loop OR
b) Remove the 'If....' statement, and add objRegEx.global = true to your regular expression.
[;)]
1. To perform a case-insensitive regular expression, you should just use objRegEx.ignoreCase = true.
2. You say:
If colMatches.Count = 1 Then
For Each strMatch in
So in other words, if there's only one match, then loop through all the matches? Uh? That doesn't make sense. So, either:
a) Remove the 'For each....' loop OR
b) Remove the 'If....' statement, and add objRegEx.global = true to your regular expression.
[;)]
![](/build/static/general/appdeploy_logo.png)
so that the conversation will remain readable.