why won't this vbscript work in Win XP 64-bit environment?
This script works on a Windows 7 x64 PC and a Windows XP x86 PC, but not on a Windows XP X64 PC, and I don't know why.
strComputer = "."
Set objNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
' Check if a user is logged in and if so, report back who it is
For Each objComputer in colComputer
If IsNull(objComputer.UserName) Then
' typically we'd run this ONLY when a user is already logged in, so this scenario shouldn't happen,
' but let's thrown in a Quit command just in case.
WScript.Quit
Else
'WScript.Echo "Logged-on user: " & objComputer.UserName
' parse string to remove the domain name
myStr = objComputer.UserName
tokens = Split(myStr,"\")
WScript.Echo tokens(1)
End If
Next
strComputer = "."
Set objNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colComputer = objWMIService.ExecQuery _
("Select * from Win32_ComputerSystem")
' Check if a user is logged in and if so, report back who it is
For Each objComputer in colComputer
If IsNull(objComputer.UserName) Then
' typically we'd run this ONLY when a user is already logged in, so this scenario shouldn't happen,
' but let's thrown in a Quit command just in case.
WScript.Quit
Else
'WScript.Echo "Logged-on user: " & objComputer.UserName
' parse string to remove the domain name
myStr = objComputer.UserName
tokens = Split(myStr,"\")
WScript.Echo tokens(1)
End If
Next
0 Comments
[ + ] Show comments
Answers (1)
Please log in to answer
Posted by:
dchristian
12 years ago
Hey RonW,
I just tested this on an x64 xp machine and it returned the logged in user.
What are you using to run the script?
I just tested this on an x64 xp machine and it returned the logged in user.
What are you using to run the script?
Comments:
-
I'm using a program called VbsEdit and can step through the code. Also can double-click it to run it, and also tried calling it from a command line w/ cscript.exe. None of these return anything. Script runs without erroring, but I get no username. Have tried on multiple XP 64 PCs where I work, and same result.
Stepping through the code, the line that's problematic is:
If IsNull(objComputer.UserName) Then
This is "IsNull" on my XP x64 PCs, but not on any of the others. Not sure why. - RonW 12 years ago