Jump to content

Recommended Posts

Posted

Hey all,

 

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:

 

Option Explicit

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

Next

 

stringArray = Split(objOS)

for counter=0 to UBound(stringArray)

if (stringArray(counter)=strOS) then

Wscript.Echo "Windows XP"

Exit for

End if

if (stringArray(counter)=str7) then

Wscript.Echo "Windows 7"

Exit for

End if

next

WSCript.Quit

 

' End of WMI Win32_OperatingSystem VBScript

Posted

The two things I can think of are....

 

Is there a firewall running on the remote server? and if so is it set to allow WMI queries through?

 

And also try setting the impersonation level for authentication on the remote server.

 

I have a script that gets the current user of the remote machine that works using WMI. Dont know if it will help so I will paste the appropriate piece of code below.

 

Function GetLocallyLoggedOnUser(strComputer)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")  

Set colComputer = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
 
For Each objComputer in colComputer
	'WScript.Echo " " & objComputer.UserName
    GetLocallyLoggedOnUser = objComputer.UserName
Next
End Function

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...