Jump to content

Recommended Posts

Posted

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')

Posted

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)
  • 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
×
×
  • Create New...