Determine Locally Logged On UserID

Discussion in 'Scripting' started by Michael Carter, Jan 28, 2004.

  1. I'm researching how to write a VBScript using WMI and/or ADSI to determine
    the locally logged on UserID for remote desktops and servers. I'm trying
    the following code but I get many null returns where I know a user is logged
    onto the pc. I've used the PSLoggedOn SysInternals Tool but I need to
    incorporate this code into a larger script.

    Does anyone have a better, more reliable solution?

    Thanks,

    Mike

    ------------------------------
    ComputerName = InputBox("Enter the name of the computer you wish to query")
    who = "winmgmts:{impersonationLevel=impersonate}!//"& ComputerName &""
    Set Users = GetObject( who ).InstancesOf ("Win32_ComputerSystem")
    for each User in Users
    MsgBox "The user name for the specified computer is: " & User.UserName
    Next
    ------------------------------
     
    Michael Carter, Jan 28, 2004
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.