Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to search a text string 1

Status
Not open for further replies.

Mohammed1972

IS-IT--Management
Sep 7, 2009
2
CA
I am not a programmer and I need to do the following:
- Obtain OS version via WMI (I know how to get this)
- Query the OS version result for a specific word (I don't know this)
- If word is found then quit, otherwise continue (I don't know this)

Below is the code I have written for obtaining OS version:
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
For Each objOperatingSystem in colOperatingSystems
Wscript.Echo objOperatingSystem.Caption & _
" " & objOperatingSystem.Version
Next

I want to query the result for word "Server" and if found then run the code below (inventory software):

Set oShell = CreateObject("WScript.Shell")
StrUser = oShell.ExpandEnvironmentStrings("%USERNAME%")
Set objNetwork = CreateObject("Wscript.Network")
strComputer = objNetwork.ComputerName
Set objFSO = CreateObject("Scripting.FileSystemObject")
Path = objFSO.GetAbsolutePathName("\\fileserver\inventory$\"&StrComputer&"-"&StrUser&".tsv")
GetName = objFSO.GetFileName(Path)
If objFSO.FileExists(path) Then
wscript.quit
Else
Set objTextFile = objFSO.CreateTextFile(Path, True)
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery ("SELECT * FROM Win32_Product")
objTextFile.WriteLine "Caption" & vbtab & "Description" & vbtab & "Name" & vbtab & "Vendor" & vbtab & "Version"
For Each objSoftware in colSoftware
objTextFile.WriteLine objSoftware.Caption & vbtab & objSoftware.Description & vbtab & objSoftware.Name & vbtab & objSoftware.Vendor & vbtab & objSoftware.Version
Next
objTextFile.Close
End if
 
[tt]For Each objOperatingSystem in colOperatingSystems
Wscript.Echo objOperatingSystem.Caption & _
" " & objOperatingSystem.Version

[blue]if instr(1,objOperatingSystem.Caption,"Server",1)<>0 then
'put the lines you want to executes when found "Server"
end if[/blue]
Next
[/tt]
 
Thanks Tsuji, I fixed the problem before I checked my email and my solution is exactly what you mentioned.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top