/build/static/layout/Breadcrumb_cap_w.png

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

0 Comments   [ + ] Show comments

Answers (1)

Posted by: dchristian 12 years ago
Red Belt
0
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?

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

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

View more:

Link

Related Links

Post

Related Posts

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ