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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win32_ComputerSystem: UserName with Windows 2000

Status
Not open for further replies.

Monkey36

MIS
May 23, 2005
60
GB
Hi all -

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.
 
Since you are connecting to WMI to get the computer name, my first instinct would be to compare the version of WMI on your XP box to the version on the 2K box that doesn't work to see if they are the same or not.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I have definitely encountered cases where WMI class properties have differed between XP and 2000, but I just checked on a Win2K Server and it shows that UserName and Name are both valid. Are there different versions of WMI for different versions of Windows 2000 or Service Packs?

Try downloading the WMI Scriptomatic from Microsoft and see what is available when running it from your Windows 2000 box. It pulls the WMI class info from the machine that it is running on.
 
I just had a look on the machines and the XP machines list the WMI BuildVersion as .2600.0000 while the 2000 machines list it as .1085.0005

However, as kmcferrion points out, UserName is valid for both versions of WMI - I don't get an error when retrieving the property, I just don't get a value returned!

I'm pulling my hair out here - has anyone got any suggestions?

Update: To make matters worse, it now seems that one of the Windows 2000 machines works Ok but two others don't, and they all have the WMI versions listed above. They should be identical builds, and I just can't see what could be causing this problem!!

I'm tearing my hair out now - can anyone offer further help?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top