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
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Community Chosen Answer

2
pcname = UCase(WshNetwork.ComputerName)
Answered 12/27/2010 by: pjgeutjens
Red Belt

Please log in to comment
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Thank you!
Answered 12/27/2010 by: taz081175
Senior Yellow Belt

Please log in to comment
0
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.

[;)]
Answered 12/27/2010 by: captain_planet
Third Degree Brown Belt

Please log in to comment
Answer this question or Comment on this question for clarity