Jump to content

Username


 Share

Recommended Posts

Having the computername of a remote computer I would like to retreive the username that is logged on that machine.

Found it:

$sUserName = RegRead('\\' & $strComputername" & '\' & 'HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\WinLogon', 'DefaultUserName')

Link to comment
Share on other sites

That registry key is the last user login. It doesn't necessarily mean that the machine is logged into. Use this to determin the user logged into the Console session. (I say console because this method doesn't return terminal sessions)

$strHost = "."
$objWMIService = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $strHost & "\root\cimv2")
$colItems = $objWMIService.ExecQuery("Select * from Win32_ComputerSystem")
For $objItem In $colItems
    $strCurrentUser = $objItem.UserName
Next
msgbox(0,"Logged On User",$strCurrentUser)
Link to comment
Share on other sites

  • 3 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...