Hi all -
I'm using this script which I've seen posted all over the net, apparently without the problems I'm encountering.
This works fine when I'm on a Windows XP computer and I'm querying another XP machine. However, if I try to query a Windows 2000 computer then the UserName property is always returned as blank.
I just can't find anywhere that explains this or offers warning - my gooling is really letting me down today!
Can anyone tell me what I should be doing to correct this?
Thanks a lot in advance,
Dan.
I'm using this script which I've seen posted all over the net, apparently without the problems I'm encountering.
Code:
strComputer = "CH04"
[COLOR=green]' Connect to computer through WMI[/color]
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputers = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
[COLOR=green]' Check information was actually retrieved[/color]
If (colComputers is Nothing) Then
WScript.Quit
End If
If (colComputers.Count = 0) Then
WScript.Quit
End If
[COLOR=green]' Loop through collection to retrieve UserName (there should only be one
' item in the collection)[/color]
For Each objComputer In colComputers
WScript.Echo "ComputerName: " & objComputer.Name
If (IsNull(objComputer.UserName)) Then
WScript.Echo "Null UserName"
Else
WScript.Echo "User: " & objComputer.UserName
End If
Next
This works fine when I'm on a Windows XP computer and I'm querying another XP machine. However, if I try to query a Windows 2000 computer then the UserName property is always returned as blank.
I just can't find anywhere that explains this or offers warning - my gooling is really letting me down today!
Can anyone tell me what I should be doing to correct this?
Thanks a lot in advance,
Dan.