;- This function returns the user who is logged in on a remote machine, provided you know the proper admin credentials of the remote machine.
; This assumes you either have ONE domain or local accounts (can be changed easily).
; In our environment we (the admins) only have LOCAL adminrights, our useraccounts are no domainadminaccounts.
; you can rewrite this script so that you can use domainadminaccounts whatever.
; one problem remains: execution of the script does take a while (as in a few seconds). tested on win2k and winxp (both local and remote)
; no extratools needed, tasklist is already preinstalled in windows
; p.s: i know this code is ugly as hell, but it works ;)
#include <String.au3>
Func _GetUserName($hostname,$admaccount,$adminpw,$domain)
Local $process = Run("tasklist /v /fo list /fi ""IMAGENAME eq explorer.exe"" " & "/s "& $hostname & " /u " & $hostname & "\" & $admaccount & " /p " & $adminpw, "", @SW_HIDE, 2)
Local $_buffer = ''
Local $Result
Local $exploreruser
Do
$_buffer &= StdoutRead($process)
Until @error
If StringReplace($_buffer, 'explorer.exe', '') <> $_buffer Then
If StringReplace($_buffer, $domain & '\', '') <> $_buffer Then
;Show Domainuser
$exploreruser = _StringBetween($_buffer,$domain & "\",@CRLF)
Return $exploreruser[0]& " (Domain account!)"
Else
;No domainuser, show local logged in account
$exploreruser = _StringBetween($_buffer,$hostname&"\",@CRLF)
Return $exploreruser[0] & " (Local account!)"
EndIf
Else
Return "no user logged in locally (or no windows OS :D)"
EndIf
EndFunc
;Example usage
;~ $hostname = "machine1"
;~ $admaccount = "administrator"
;~ $adminpw = "foo"
;~ $domain = "domain"
;~ MsgBox(1,"Currently logged in user on " & $hostname & " is:",_GetUserName($hostname,$admaccount,$adminpw,$domain))
though it is ugly and i still have to parse cmd, it suits my needs. this script is working, take it