hendrikhe Posted August 17, 2017 Share Posted August 17, 2017 (edited) Hello, I am running a script with a different user that has admin rights, but I need the current logged in username. The script below works on my computer and also on my VMWare machines (all Windows 7) But for some reason it is not working at my company computer (username is empty). Even executing with local admin. The only difference that I know is that the company computer is in a domain... Any advise or workarounds? #include<_ProcessFunctions.au3> $hProcess = _ProcessOpen(ProcessExists("explorer.exe"),0x20000) MsgBox(0,"",_ProcessGetOwner($hProcess)) _ProcessCloseHandle($hProcess) Edited August 17, 2017 by hendrikhe Link to comment Share on other sites More sharing options...
Deye Posted August 17, 2017 Share Posted August 17, 2017 What do you get for @UserName, Maybe try this function Link to comment Share on other sites More sharing options...
hendrikhe Posted August 18, 2017 Author Share Posted August 18, 2017 (edited) Thank you Deye, I changed the script a bit and I believe that I must be high . I simply cant believe what is happening. The script below works in my home computer/vmware. But it only works partially on company computer. it displays an empty username on company computer: MsgBox(0, '', $username) but you can see the username name on Array (see attached screenshot), Whats going on ? expandcollapse popup#include<_ProcessFunctions.au3> #Include <ScreenCapture.au3> #include <WinAPIFiles.au3> #Include <Misc.au3> #include <WinAPI.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> #include <Array.au3> #include <Clipboard.au3> #include <File.au3> #include <GuiIPAddress.au3> #include <TreeViewConstants.au3> #include <AVIConstants.au3> #include <WinAPI.au3> #include <WinAPISys.au3> ;~ #include "CompInfo.au3" #include <TrayConstants.au3> ; Required for the $TRAY_ICONSTATE_SHOW constant. #include <GDIPlus.au3> #include <INet.au3> #include <Date.au3> #include <array.au3> ; Needed to display array in example. #include <security.au3> ; Get OWNER from SID. $tag_WTS_PROCESS_INFO= _ "DWORD SessionId;" & _ "DWORD ProcessId;" & _ "PTR pProcessName;" & _ "PTR pUserSid" ; ############ Example code ####################### ;~ MsgBox(0,"Process by name or number(PID)", "'Owner' of Explorer.exe is " & _ProcessListOWNER_WTS("Explorer.exe")) $temp=_ProcessListOWNER_WTS() $temp[0][0]="Process" $temp[0][1]="ProcessId" $temp[0][2]="SessionId" $temp[0][3]="ProcessOWNER" $username = 0 $i = 0 ;--- search for explorer.exe in array While $temp[$i][0] <> "explorer.exe" $i = $i+1 WEnd ;--- assign $username and $process from "while" above if $temp[$i][0] = "explorer.exe" Then $username = $temp[$i][3] $process = $temp[$i][0] EndIf ;-- display ysername and process MsgBox(0, '', $username) MsgBox(0, '', $process) _ArrayDisplay($temp, "Process list with OWNER...") ; ############ Here be func! #################### Func _ProcessListOWNER_WTS($PID=0) Local $i, $ret, $ret1, $mem $ret=DllCall("WTSApi32.dll", "int", "WTSEnumerateProcesses", "int", 0, "int", 0, "int", 1, "ptr*", 0, "int*", 0) Local $array[$ret[5]][4] $mem=DllStructCreate($tag_WTS_PROCESS_INFO,$ret[4]) for $i=0 to $ret[5]-1 $mem=DllStructCreate($tag_WTS_PROCESS_INFO, $ret[4]+($i*DllStructGetSize($mem))) ;if DllStructGetData($mem, "pProcessName") Then $string=DllStructCreate("char[256]", DllStructGetData($mem, "pProcessName")) $array[$i][0]=DllStructGetData($string,1) ;EndIf $array[$i][1]=DllStructGetData($mem, "ProcessId") $array[$i][2]=DllStructGetData($mem, "SessionId") ;if DllStructGetData($mem, "pUserSid") Then $ret1 = _Security__LookupAccountSid(DllStructGetData($mem, "pUserSid")) if IsArray($ret1) Then $array[$i][3]=$ret1[0] ;EndIf Next DllCall("WTSApi32.dll", "int", "WTSFreeMemory", "int", $ret[4]) if $PID Then if IsInt($PID) Then for $i=0 to UBound($array, 1) - 1 if $array[$i][1] = $PID Then Return $array[$i][3] EndIf Next Else for $i=0 to UBound($array, 1) - 1 if $array[$i][0] = $PID Then Return $array[$i][3] EndIf Next EndIf EndIf Return $array EndFunc ;################################ END FUNC ########################################## Edited August 18, 2017 by hendrikhe change Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now