Manko Posted March 2, 2009 Share Posted March 2, 2009 (edited) Hi!DOES NOT need admin rights.W2K and up...expandcollapse popup#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" _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 ##########################################/Manko [Edit: Added getting OWNER of select process.] Edited April 13, 2010 by Manko Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually... Link to comment Share on other sites More sharing options...
KaFu Posted March 2, 2009 Share Posted March 2, 2009 (edited) That's the way I like it . Great functions pop-up these days... keep on competing Manko and ascendant ! Edited March 2, 2009 by KaFu  OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Manko Posted March 2, 2009 Author Share Posted March 2, 2009 That's the way I like it . Great functions pop-up these days... keep on competing Manko and ascendant !Thanks! Ascendants post reminded me that I had been looking at WTS api calls a while back, but was a little lazy... /Manko Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually... Link to comment Share on other sites More sharing options...
Ascend4nt Posted March 2, 2009 Share Posted March 2, 2009 Nice job. We shall soon kill the need for WMI for good! mwahaha My contributions: Performance Counters in Windows - Measure CPU, Disk, Network etc Performance | Network Interface Info, Statistics, and Traffic | CPU Multi-Processor Usage w/o Performance Counters | Disk and Device Read/Write Statistics | Atom Table Functions | Process, Thread, & DLL Functions UDFs |Â Process CPU Usage Trackers | PE File Overlay Extraction | A3X Script Extract | File + Process Imports/Exports Information | Windows Desktop Dimmer Shade | Spotlight + Focus GUI - Highlight and Dim for Eyestrain Relief | CrossHairs (FullScreen) |Â Rubber-Band Boxes using GUI's (_GUIBox) | GUI Fun! | IE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) | Magnifier (Vista+) Functions UDF | _DLLStructDisplay (Debug!) | _EnumChildWindows (controls etc) | _FileFindEx | _ClipGetHTML | _ClipPutHTML + ClipPutHyperlink | _FileGetShortcutEx | _FilePropertiesDialog | I/O Port Functions | File(s) Drag & Drop | _RunWithReducedPrivileges | _ShellExecuteWithReducedPrivileges | _WinAPI_GetSystemInfo | dotNETGetVersions | Drive(s) Power Status | _WinGetDesktopHandle | _StringParseParameters | Screensaver, Sleep, Desktop Lock Disable | Full-Screen Crash Recovery Wrappers/Modifications of others' contributions: _DOSWildcardsToPCRegEx (original code: RobSaunder's) | WinGetAltTabWinList (original: Authenticity) UDF's added support/programming to: _ExplorerWinGetSelectedItems | MIDIEx UDF (original code: eynstyne) (All personal code/wrappers centrally located at Ascend4nt's AutoIT Code) Link to comment Share on other sites More sharing options...
ptrex Posted March 3, 2009 Share Posted March 3, 2009 @MankoVery nice indead. Maybe you can align the function name with Ascendant. Using his naming convention _WinAPI_ProcessListOWNER_WTSThis way it clearly identifies that it is not WMI related.Just a thoughtRgds,ptrex Contributions :Firewall Log Analyzer for XP - Creating COM objects without a need of DLL's - UPnP support in AU3Crystal Reports Viewer - PDFCreator in AutoIT - Duplicate File FinderSQLite3 Database functionality - USB Monitoring - Reading Excel using SQLRun Au3 as a Windows Service - File Monitor - Embedded Flash PlayerDynamic Functions - Control Panel Applets - Digital Signing Code - Excel Grid In AutoIT - Constants for Special Folders in WindowsRead data from Any Windows Edit Control - SOAP and Web Services in AutoIT - Barcode Printing Using PS - AU3 on LightTD WebserverMS LogParser SQL Engine in AutoIT - ImageMagick Image Processing - Converter @ Dec - Hex - Bin -Email Address Encoder - MSI Editor - SNMP - MIB ProtocolFinancial Functions UDF - Set ACL Permissions - Syntax HighLighter for AU3ADOR.RecordSet approach - Real OCR - HTTP Disk - PDF Reader Personal Worldclock - MS Indexing Engine - Printing ControlsGuiListView - Navigation (break the 4000 Limit barrier) - Registration Free COM DLL Distribution - Update - WinRM SMART Analysis - COM Object Browser - Excel PivotTable Object - VLC Media Player - Windows LogOnOff Gui -Extract Data from Outlook to Word & Excel - Analyze Event ID 4226 - DotNet Compiler Wrapper - Powershell_COM - New Link to comment Share on other sites More sharing options...
Digisoul Posted March 3, 2009 Share Posted March 3, 2009 Hi! DOES NOT need admin rights. I'm quite satisfied! It IS W2K up only though... expandcollapse popup#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 ####################### $temp=_ProcessListOWNER_WTS() $temp[0][0]="Process" $temp[0][1]="ProcessId" $temp[0][2]="SessionId" $temp[0][3]="ProcessOWNER" _ArrayDisplay($temp, "Process list with OWNER...") ; ############################################### ; ############ Here be func! #################### Func _ProcessListOWNER_WTS() $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*16)) ;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]) Return $array EndFunc ;################################ END FUNC ########################################## /Manko Hi Manko, I need a bit of your help, its out of topic but hope so you will not mind. actually i want the SID of Currently Active User, means the user who uses the Desktop, and if there is no active user the (mentioned) function will return false or 0. Currently im using 2 methods 1. from sys32\query.exe 2. WMI 1st method uses much cpu, bcoz i have to track the Active User. 2nd method work well, but in loop it will fail some time. 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
Manko Posted March 3, 2009 Author Share Posted March 3, 2009 Hi Manko,I need a bit of your help, its out of topic but hope so you will not mind. actually i want the SID of Currently Active User, means the user who uses the Desktop, and if there is no active user the (mentioned) function will return false or 0. Currently im using 2 methods1. from sys32\query.exe2. WMI1st method uses much cpu, bcoz i have to track the Active User.2nd method work well, but in loop it will fail some time.Hi!Hmm... I want a googeling... Could take days to get something worthwhile... Most threads talked about getting SID from processes or threads, but some talked of WMI...I was thinking to myself, why not use SID of explorer.exe, and sure enough, I found someone who used that method.So, just mod this function, and grab SID from explorer.exe... ...or keep googling. That's what I always do... Tedious, but ultimately rewarding! (You find scraps and experiment and expand... sorta... nough words!)/Manko Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually... Link to comment Share on other sites More sharing options...
ProgAndy Posted March 3, 2009 Share Posted March 3, 2009 It should work with LookupAccountName expandcollapse popup#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 ####################### $temp=_ProcessListOWNER_WTS() $temp[0][0]="Process" $temp[0][1]="ProcessId" $temp[0][2]="SessionId" $temp[0][3]="ProcessOWNER" $temp[0][4]="Owner SID" $temp[0][5]="Current User Process" _ArrayDisplay($temp, "Process list with OWNER...") ; ############################################### ; ############ Here be func! #################### Func _ProcessListOWNER_WTS() $ret=DllCall("WTSApi32.dll", "int", "WTSEnumerateProcesses", "int", 0, "int", 0, "int", 1, "ptr*", 0, "int*", 0) Local $array[$ret[5]][6], $Current_User_SID = _GetCurrentUserSID() $mem=DllStructCreate($tag_WTS_PROCESS_INFO,$ret[4]) for $i=0 to $ret[5]-1 $mem=DllStructCreate($tag_WTS_PROCESS_INFO, $ret[4]+($i*16)) ;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] $array[$i][4]=_Security__SidToStringSid(DllStructGetData($mem, "pUserSid")) $array[$i][5]=$Current_User_SID=$array[$i][4] EndIf ;EndIf Next DllCall("WTSApi32.dll", "int", "WTSFreeMemory", "int", $ret[4]) Return $array EndFunc ;################################ END FUNC ########################################## Func _GetCurrentUserSID() ; Prog@ndy Local $User = _Security__LookupAccountName(@UserName,@ComputerName) If @error Then Return SetError(1,0,"") Return $User[0] EndFunc *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Manko Posted March 3, 2009 Author Share Posted March 3, 2009 @ProgAndy Cool, expansion! I foolishly assumed he was working through a service, in which case my ass-umptions would have been sensible... hrm... If ones OWN process doing the checking is running as the user, it's easy... Which is it? /Manko Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually... Link to comment Share on other sites More sharing options...
trancexx Posted March 3, 2009 Share Posted March 3, 2009 ass-umptions Nice function.Unicode would be nice too (maybe even in combination with lstrlenW). ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Digisoul Posted March 4, 2009 Share Posted March 4, 2009 Thanks Manko, for your Reply. It should work with LookupAccountName Func _GetCurrentUserSID() ; Prog@ndy Local $User = _Security__LookupAccountName(@UserName,@ComputerName) If @error Then Return SetError(1,0,"") Return $User[0] EndFuncThanks for this function ProgAndy, 1 more question, we have to mention the User Name in your function. In my case i am using my script as service process, so if i mention @UserName in function, it will return me the SID of System Account not the user of Desktop. hope so its clear the concept of my need. thanks in advance for your kind help. 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
Manko Posted March 4, 2009 Author Share Posted March 4, 2009 Thanks Manko, for your Reply.In my case i am using my script as service process, so if i mention @UserName in function, it will return me the SID of System Account not the user of Desktop.hope so its clear the concept of my need.thanks in advance for your kind help.Hi!Hehe... My assumptions were correct! Try the method I suggested!Just change MY function to only return SID of explorer.exe... Since explorer is desktop of current user, it should do you right! If you need help with that, just PM or reply again./Manko Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually... Link to comment Share on other sites More sharing options...
Digisoul Posted March 4, 2009 Share Posted March 4, 2009 Hi! Hehe... My assumptions were correct! Try the method I suggested! Just change MY function to only return SID of explorer.exe... Since explorer is desktop of current user, it should do you right! If you need help with that, just PM or reply again. /MankoYa , thanks Manko. i done as you said. Its work now! here is my modification Func _Active_account($givenPID) $ret=DllCall("WTSApi32.dll", "int", "WTSEnumerateProcesses", "int", 0, "int", 0, "int", 1, "ptr*", 0, "int*", 0) $mem=DllStructCreate($tag_WTS_PROCESS_INFO,$ret[4]) for $i=0 to $ret[5]-1 $mem=DllStructCreate($tag_WTS_PROCESS_INFO, $ret[4]+($i*16)) If DllStructGetData($mem, "ProcessId") = $givenPID Then $ret1 = _Security__LookupAccountSid(DllStructGetData($mem, "pUserSid")) if IsArray($ret1) Then DllCall("WTSApi32.dll", "int", "WTSFreeMemory", "int", $ret[4]) Return $ret1[0] EndIf EndIf Next DllCall("WTSApi32.dll", "int", "WTSFreeMemory", "int", $ret[4]) Return False EndFunc I used it when i need the UserName, if you can improve it so plz.. 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
ProgAndy Posted March 4, 2009 Share Posted March 4, 2009 Try this: This func retrieves the username from the current session. But now, this is really OT #include<Security.au3> Func _GetCurrentUser() Local $result = DllCall("Wtsapi32.dll","int", "WTSQuerySessionInformationW", "Ptr", 0, "int", -1, "int", 5, "ptr*", 0, "dword*", 0) If @error Or $result[0] = 0 Then Return SetError(1,0,"") Local $User = DllStructGetData(DllStructCreate("wchar[" & $result[5] & "]" , $result[4]),1) DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr", $result[4]) Return $User EndFunc Func _GetCurrentUserSID() ; Prog@ndy Local $User = _Security__LookupAccountName(_GetCurrentUser(),@ComputerName) If @error Then Return SetError(1,0,"") Return $User[0] EndFunc MsgBox(0, '', _GetCurrentUser() & @CRLF & _GetCurrentUserSID()) *GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes Link to comment Share on other sites More sharing options...
Manko Posted March 4, 2009 Author Share Posted March 4, 2009 (edited) Try this: This func retrieves the username from the current session. But now, this is really OT You may be offtopic but this function , WTSQuerySessionInformation, is really great!http://msdn.microsoft.com/en-us/library/aa383838(VS.85).aspxLot's of uses. I was sniffing through the WTS-functions, but I missed that one... ??Great work!/Manko Edited March 4, 2009 by Manko Yes i rush things! (I sorta do small bursts inbetween doing nothing.) Things I have rushed and reRushed:* ProDLLer - Process manager - Unload viri modules (dll) and moore...* _WinAPI_ProcessListOWNER_WTS() - Get Processes owner list...* _WinAPI_GetCommandLineFromPID() - Get commandline of target process...* _WinAPI_ThreadsnProcesses() Much info if expanded - optional Indented "Parent/Child"-style Processlist. Moore to come... eventually... Link to comment Share on other sites More sharing options...
Digisoul Posted March 4, 2009 Share Posted March 4, 2009 Try this: This func retrieves the username from the current session. But now, this is really OT #include<Security.au3> Func _GetCurrentUser() Local $result = DllCall("Wtsapi32.dll","int", "WTSQuerySessionInformationW", "Ptr", 0, "int", -1, "int", 5, "ptr*", 0, "dword*", 0) If @error Or $result[0] = 0 Then Return SetError(1,0,"") Local $User = DllStructGetData(DllStructCreate("wchar[" & $result[5] & "]" , $result[4]),1) DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr", $result[4]) Return $User EndFunc Func _GetCurrentUserSID() ; Prog@ndy Local $User = _Security__LookupAccountName(_GetCurrentUser(),@ComputerName) If @error Then Return SetError(1,0,"") Return $User[0] EndFunc MsgBox(0, '', _GetCurrentUser() & @CRLF & _GetCurrentUserSID()) Thanks for this function, thats exactly wat i want! @Manko Thanks 4 your help & that link. 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
Digisoul Posted March 5, 2009 Share Posted March 5, 2009 Try this: This func retrieves the username from the current session. But now, this is really OT #include<Security.au3> Func _GetCurrentUser() Local $result = DllCall("Wtsapi32.dll","int", "WTSQuerySessionInformationW", "Ptr", 0, "int", -1, "int", 5, "ptr*", 0, "dword*", 0) If @error Or $result[0] = 0 Then Return SetError(1,0,"") Local $User = DllStructGetData(DllStructCreate("wchar[" & $result[5] & "]" , $result[4]),1) DllCall("Wtsapi32.dll", "int", "WTSFreeMemory", "ptr", $result[4]) Return $User EndFunc Func _GetCurrentUserSID() ; Prog@ndy Local $User = _Security__LookupAccountName(_GetCurrentUser(),@ComputerName) If @error Then Return SetError(1,0,"") Return $User[0] EndFunc MsgBox(0, '', _GetCurrentUser() & @CRLF & _GetCurrentUserSID()) Your function work well for 1 account only, if user switch to other login it will still give the Old User name & SID? 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
trancexx Posted March 5, 2009 Share Posted March 5, 2009 Your function work well for 1 account only, if user switch to other login it will still give the Old User name & SID?That is interesting. It could be the definition of WTS_CURRENT_SESSION maybe. Try this: #include <Security.au3> MsgBox(0, '', _GetCurrentUser() & @CRLF & _GetCurrentUserSID()) Func _GetCurrentUser() Local $aCall = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformationW", _ "hwnd", 0, _ ; WTS_CURRENT_SERVER_HANDLE "dword", 0, _ ; WTS_CURRENT_SESSION? "int", 5, _ ; WTSUserName "ptr*", 0, _ "dword*", 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, "") EndIf Local $sUser = DllStructGetData(DllStructCreate("wchar[" & $aCall[5] / 2 & "]", $aCall[4]), 1) DllCall("Wtsapi32.dll", "none", "WTSFreeMemory", "ptr", $aCall[4]) Return SetError(0, 0, $sUser) EndFunc Func _GetCurrentUserSID() ; Prog@ndy Local $User = _Security__LookupAccountName(_GetCurrentUser(), @ComputerName) If @error Then Return SetError(1, 0, "") Return $User[0] EndFunc ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Digisoul Posted March 5, 2009 Share Posted March 5, 2009 That is interesting. It could be the definition of WTS_CURRENT_SESSION maybe. Try this: #include <Security.au3> MsgBox(0, '', _GetCurrentUser() & @CRLF & _GetCurrentUserSID()) Func _GetCurrentUser() Local $aCall = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformationW", _ "hwnd", 0, _ ; WTS_CURRENT_SERVER_HANDLE "dword", 0, _ ; WTS_CURRENT_SESSION? "int", 5, _ ; WTSUserName "ptr*", 0, _ "dword*", 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, "") EndIf Local $sUser = DllStructGetData(DllStructCreate("wchar[" & $aCall[5] / 2 & "]", $aCall[4]), 1) DllCall("Wtsapi32.dll", "none", "WTSFreeMemory", "ptr", $aCall[4]) Return SetError(0, 0, $sUser) EndFunc Func _GetCurrentUserSID() ; Prog@ndy Local $User = _Security__LookupAccountName(_GetCurrentUser(), @ComputerName) If @error Then Return SetError(1, 0, "") Return $User[0] EndFunc thanks for the modification i'll try it. 73 108 111 118 101 65 117 116 111 105 116 Link to comment Share on other sites More sharing options...
Digisoul Posted March 29, 2009 Share Posted March 29, 2009 That is interesting. It could be the definition of WTS_CURRENT_SESSION maybe. Try this: #include <Security.au3> MsgBox(0, '', _GetCurrentUser() & @CRLF & _GetCurrentUserSID()) Func _GetCurrentUser() Local $aCall = DllCall("Wtsapi32.dll", "int", "WTSQuerySessionInformationW", _ "hwnd", 0, _ ; WTS_CURRENT_SERVER_HANDLE "dword", 0, _ ; WTS_CURRENT_SESSION? "int", 5, _ ; WTSUserName "ptr*", 0, _ "dword*", 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, "") EndIf Local $sUser = DllStructGetData(DllStructCreate("wchar[" & $aCall[5] / 2 & "]", $aCall[4]), 1) DllCall("Wtsapi32.dll", "none", "WTSFreeMemory", "ptr", $aCall[4]) Return SetError(0, 0, $sUser) EndFunc Func _GetCurrentUserSID() ; Prog@ndy Local $User = _Security__LookupAccountName(_GetCurrentUser(), @ComputerName) If @error Then Return SetError(1, 0, "") Return $User[0] EndFunc Its still not working, only work once after that allways return "" string. 73 108 111 118 101 65 117 116 111 105 116 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