Jump to content
Sign in to follow this  
Stucky

Username

Recommended Posts

Stucky

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

Share this post


Link to post
Share on other sites
Andreik

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

@UserName

When the words fail... music speaks

Share this post


Link to post
Share on other sites
Stucky

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

Share this post


Link to post
Share on other sites
spudw2k

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)

Share this post


Link to post
Share on other sites
gcue

I got this to work only if I was the user logged on to the remote system =/

Share this post


Link to post
Share on other sites

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
Sign in to follow this  

×