Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


wildcard's for IF...THEN?

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,2518
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> wildcard's for IF...THEN?
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 wildcard's for IF...THEN? - 3/30/2005 4:49:21 AM   
  strcdply

 

Posts: 20
Score: 0
Joined: 3/30/2005
From:
Status: offline
I am wanting to take this script:

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery(_
"Select * from Win32_Product " & _
"Where IdentifyingNumber =" _
& " '{90280409-6000-11D3-8CFE-0050048383C9}'")
For Each objItem in colSoftware
Wscript.Echo "Name: " & objItem.Name
Wscript.Echo "Version: " & objItem.Version
Next

and include in the For..Next statment an IF..Then statement that does a comparison of objItem.Name with a string that contains a wild card. I know that the syntax below is INCORRECT but something to the effect of:

If objItem.Version LIKE "10%" THEN
Wscript.Echo "Blah Blah Blah"
END IF
 
 
Post #: 1
 
 Re: wildcard's for IF...THEN? - 3/30/2005 5:29:38 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
You can't use wildcards but you could check for a string using Instr, LEFT, RIGHT, or MID

If instr(objItem.Name,"10) > 0 then
OR
If Left(objItem.Name,2) = "10" then

etc. Take a look at the WSH docs if you want more info on the above.

(in reply to strcdply)
 
 
Post #: 2
 
 Re: wildcard's for IF...THEN? - 3/30/2005 5:32:33 AM   
  strcdply

 

Posts: 20
Score: 0
Joined: 3/30/2005
From:
Status: offline
Thanks Mike. That's exactly what I needed.

(in reply to strcdply)
 
 
Post #: 3
 
 Re: wildcard's for IF...THEN? - 3/30/2005 6:27:10 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
strcdply, can you adapt your script to the next
construction with the wildcard :

' Description
' Returns a list of all the folders whose path begins with C:\S.
' This script runs only under Windows XP or Windows .NET Server.

' Script Code

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name Like '%c:\\S%'")
For Each objFolder in colFolders
Wscript.Echo "Name: " & objFolder.Name
Next

Source : "System Administration Scripting Guide"
In the "where" clause I assume that you can have several
conditions combined with AND or OR logical operators.
Good luck.

< Message edited by didorno -- 7/20/2005 7:48:47 AM >

(in reply to strcdply)
 
 
Post #: 4
 
 Re: wildcard's for IF...THEN? - 3/30/2005 6:58:36 AM   
  strcdply

 

Posts: 20
Score: 0
Joined: 3/30/2005
From:
Status: offline
didorno,

thanks for the response. I will definitely keep that in mind for future scripts. unfortunately i have win 2000 clients as well and if i am not mistaken the LIKE operator is not supported for them:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/like_operator.asp

(in reply to strcdply)
 
 
Post #: 5
 
 Re: wildcard's for IF...THEN? - 3/31/2005 6:46:56 AM   
  didorno

 

Posts: 361
Score: 0
Joined: 2/12/2005
From:
Status: offline
It's a pity.

(in reply to strcdply)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> wildcard's for IF...THEN? Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts