Scripting Question

Case sensitive

12/27/2010 2655 views
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]

End If

0 Comments   [ + ] Show comments


Community Chosen Answer

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

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

All Answers

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

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
Black Belt

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login


This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ