objWMIService.ExecQuery

Anything VBScript-related, including Windows Script Host, WMI, ADSI, and more.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
milend1966
Posts: 7
Joined: Wed Feb 01, 2012 12:39 am

objWMIService.ExecQuery

Post by milend1966 » Tue Feb 28, 2012 1:29 am

Hi, i need to run the script below:'On Error Resume NextstrComputer = "."Wscript.Echo "PC "&strComputer Set objWMIService = GetObject("winmgmts:" & strComputer & "rootcimv2")Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)For Each objItem in colItems Wscript.Echo "UserName: " & objItem.UserName NextMy problem is that on lab PC it works and returns the user logged on, on production PC it returns null value. The operative system is the same W2003 EE. I know that there are other ways to retrieve this information, but i need to know why objItem.UserName does not work always...thanks

User avatar
milend1966
Posts: 7
Joined: Wed Feb 01, 2012 12:39 am

objWMIService.ExecQuery

Post by milend1966 » Tue Feb 28, 2012 3:37 am

I'm querying remotely by RDP....

Locked