Connecting to a remote computer using VBScript
I am trying to create a script that connects to a remote computer to get the OS that is running on it. It is a fairly simple code that I have written, and though it works for the local computer, as soon as I change the strComputer to a remote computer name it does nothing. I am querying this info out of Windows Server 2008 database. Think you can help?
Here is my code:
Dim objWMIService, objItem, colItems, counter
Dim strComputer, strList, objOS, stringArray
On Error Resume Next
strComputer = "."
strOS = "XP"
str7 = "7"
' WMI Connection to the object in the CIM namespace
Set objWMIService = GetObject("winmgmts:\\" _
& strComputer & "\root\cimv2")
' WMI Query to the Win32_OperatingSystem
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
' For Each... In Loop (Next at the very end)
For Each objItem in colItems
objOS=objItem.Caption & VbCr
stringArray = Split(objOS)
for counter=0 to UBound(stringArray)
if (stringArray(counter)=strOS) then
Wscript.Echo "Windows XP"
if (stringArray(counter)=str7) then
Wscript.Echo "Windows 7"
' End of WMI Win32_OperatingSystem VBScript