Skitty Posted March 28, 2012 Share Posted March 28, 2012 I've stumbled into an issue related to retrieving a file name / path from an object handle, I can identify that the file handle is a handle for a file, but I'm stumped at getting the file name / path of which the handle is for, anyone know of any existing method implemented in autoit for doing this?Currently I'm using winapiex function _WinAPI_GetObjectNameByHandle($hObject) to validate that it is indeed a file handle but I'd love to know of how to get the actual file location of which it belongs .I've found this example but I'm not exactly fluent in moon-speak. Link to comment Share on other sites More sharing options...
guinness Posted March 28, 2012 Share Posted March 28, 2012 I mentioned this today in my LockFile UDF thread. Search WinAPIEx.au3 (it does all the moon translation for you) and then use _WinAPI_GetFinalPathNameByHandle. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kylomas Posted March 28, 2012 Share Posted March 28, 2012 ApudAngelorum, WinAPIEx.au3 comes complete with a help file. Yahied has also taken the trouble to cite MSDN links where appropriate. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
guinness Posted March 28, 2012 Share Posted March 28, 2012 ApudAngelorum,WinAPIEx.au3 comes complete with a help file. Yahied has also taken the trouble to cite MSDN links where appropriate.kylomasAgreed, he's spent alot of time improving a UDF I use practically everyday. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Skitty Posted March 28, 2012 Author Share Posted March 28, 2012 (edited) Works perfectly! Only problem is that the script freezes until I kill both instances of autoit3wrapper.exe and the script resumes operation as normal. Thanks everyone. Edit: Confirmed, for some reason the first instance of the autoit3wrapper.exe freezes my scripts operation until I kill it, but if I compile the script, everything works as expected. Edited March 28, 2012 by ApudAngelorum Link to comment Share on other sites More sharing options...
guinness Posted March 28, 2012 Share Posted March 28, 2012 Do you have a small reproducer so we can look at it. Also could you specify the version of AutoIt and SciTE4AutoIt3 you're using. UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
kylomas Posted March 28, 2012 Share Posted March 28, 2012 ApudAngelorum, I've run into something like this before. You might try setting the handle variable to 0 or "" when you are done with it. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Skitty Posted March 28, 2012 Author Share Posted March 28, 2012 ApudAngelorum,I've run into something like this before. You might try setting the handle variable to 0 or "" when you are done with it.kylomasDo you have a small reproducer so we can look at it. Also could you specify the version of AutoIt and SciTE4AutoIt3 you're using.I'm sorry, this wasn't really something wrong with the autoitwrapper, the problem was that I was performing the tests on scite which seemed to directly interfere with the operation of all of its child processes, my bad. Link to comment Share on other sites More sharing options...
guinness Posted March 28, 2012 Share Posted March 28, 2012 (edited) I've just realised who you are, I'm sure you previous handle wasn't on top of your image before. Edited March 28, 2012 by guinness UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Skitty Posted March 29, 2012 Author Share Posted March 29, 2012 I'm sorry, this wasn't really something wrong with the autoitwrapper, the problem was that I was performing the tests on scite which seemed to directly interfere with the operation of all of its child processes, my bad. Just in case anyone is looking for help and ends up here regarding a similar issue and encounters a freezing script like me, the issue was really affiliated with system file object attributes. File handles with these attributes should be avoided for some reason. 0x00120189 0x0012019f 0x00100000 Link to comment Share on other sites More sharing options...
kylomas Posted March 29, 2012 Share Posted March 29, 2012 ApudAngelorum, Was the problem that SCiTE also had the file handle? And, how did you find these particular handles? kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
guinness Posted March 29, 2012 Share Posted March 29, 2012 Like I said provide a small reproducer and then we can see if the problem is actually those attributes (whatever they may be without sifting through the MSDN.) UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 Link to comment Share on other sites More sharing options...
Skitty Posted March 29, 2012 Author Share Posted March 29, 2012 (edited) I'm sorry for the late response guys, I feel asleep right after that post, here is exactly what I was doing~ Yesterday I was sifting through yashides winapiex examples and noticed a particular function that would enumerate some of a processes open handles, it reminded me of a post by manko and monoceres, from which I took a deep look at how they were avoiding a freezing script, the end result was this. expandcollapse popup#region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Compression=4 #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <Array.au3> Global Const $hKERNEL32 = DllOpen("kernel32.dll") Global Const $hNTDLL = DllOpen("ntdll.dll") Global Const $Critical[13] = [ _; things to ignore 'winlogon.exe', _ 'services.exe', _ 'csrss.exe', _ 'smss.exe', _ 'lsass.exe', _ 'alg.exe', _ 'svchost.exe', _ 'spoolsv.exe', _ 'wdfmgr.exe', _ 'dwm.exe', _ 'logonui.exe', _ 'wininit.exe', _ 'lsm.exe' _ ] Global $ReturnInf = _ListHwnds("scite.exe") _ArrayDisplay($ReturnInf) ; #FUNCTION# ==================================================================================================================== ; Name ..........: _ListHwnds ; Description ...: Returns a list of obtainable handles in a specified process, some handles cannot be obtained. ; Syntax ........: _ListHwnds([$PID = 0[, $IgnoreSys = 0]]) ; Parameters ....: $PID - [optional] PID of process to retrieve hwnds from. Default is 0, which is all processes. ; $IgnoreSys - [optional] True to ignore system files, false otherwise. Default is false. ; $FileObject - [Internal] Ignore this parameter, it is used only by the function. ; Return values .: An array of hwnds and process inforamtion. ; Author ........: Yashied, monoceres, Manko, THAT1ANONYMOUSDUDE ; Modified ......: ; Remarks .......: This function is a compilation of different peoples code, a lot of yashideds winapiex code ; was taken to create this, the reason I took functions apart and created this frankenstein-ish function ; is for speed, I must also give credit to everyone listed in Authors because I have also taken bits and ; snips of code from them. ; Related .......: ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _ListHwnds($PID = 0,$IgnoreSys = 0, $FileObject = 0) If $PID Then $PID = ProcessExists($PID) If Not $PID Then Return SetError(1,0,0) EndIf If $FileObject = 0 Then $FileObject = _ListHwnds(False,False,-1) If @error Then Return SetError(1,0,0) EndIf Local $tSHI Local $tHandle Local $pData Local $Ret Local $Size Local $Result[1][2] Local $ResultCount Local $IgnoreList Local $Temporariis $tSHI = DllStructCreate('ulong;byte[4194304]') $Ret = DllCall($hNTDLL, 'uint', 'ZwQuerySystemInformation', 'uint', 16, 'ptr', DllStructGetPtr($tSHI), 'ulong', DllStructGetSize($tSHI), 'ulong*', 0) If @error Then Return SetError(1, 0, 0) Else If $Ret[0] Then Return SetError(1, $Ret[0], 0) EndIf EndIf $pData = DllStructGetPtr($tSHI, 2) $Size = DllStructGetSize(DllStructCreate('ulong;ubyte;ubyte;ushort;ptr;ulong')) #Region - Globalization - If $FileObject = -1 Then ;#CS ; In an attempt to make this globally operable with on a multitude of varying operating system types ; I have taken the approach of discovering the system file object type by using this messy code ; below in order to avoide depending on a static value that may not be accurate. ;#CE Local $tPOTI = DllStructCreate('ushort;ushort;ptr;byte[128]') For $i = 1 To DllStructGetData($tSHI, 1) $tHandle = DllStructCreate('ulong;ubyte;ubyte;ushort;ptr;ulong', $pData + ($i - 1) * $Size) If DllStructGetData($tHandle, 1) <> @AutoItPID Then ContinueLoop $Temporariis = Ptr(DllStructGetData($tHandle, 4)) Local $Ret2 = DllCall($hNTDLL, 'uint', 'ZwQueryObject', 'ptr', $Temporariis, 'uint', 2, 'ptr', DllStructGetPtr($tPOTI), 'ulong', DllStructGetSize($tPOTI), 'ptr', 0) If @error Then Return SetError(1, 0, 0) Else If $Ret2[0] Then Return SetError(1, 0, 0) EndIf EndIf Local $pData2 = DllStructGetData($tPOTI, 3) If Not $pData2 Then Return SetError(1, 0, 0) EndIf Local $Length = DllCall($hKERNEL32, 'int', 'lstrlenW', 'ptr', $pData2) If @error Then Return SetError(1, 0, 0) EndIf $Length = $Length[0] If @error Then Return SetError(1, 0, 0) EndIf If Not $Length Then Return SetError(1, 0, 0) EndIf Local $tString = DllStructCreate('wchar[' & ($Length + 1) & ']', $pData2) If @error Then Return SetError(1, 0, 0) EndIf If DllStructGetData($tString, 1) == "File" Then;we found the type needed Return SetError(0,0,DllStructGetData($tHandle, 2));return it so we can use it to find them EndIf Next Return SetError(1, 0, 0) EndIf #EndRegion - Globalization - Local $CurrentPID If $IgnoreSys Then For $I = 0 To UBound($Critical) - 1 $Temporariis = ProcessList($Critical[$I]) For $X = 1 To $Temporariis[0][0] $IgnoreList &= $Temporariis[$X][1] & "|"; buld a string of system PIDs to ignore Next Next EndIf For $i = 1 To DllStructGetData($tSHI, 1) $tHandle = DllStructCreate('ulong;ubyte;ubyte;ushort;ptr;ulong', $pData + ($i - 1) * $Size) $CurrentPID = DllStructGetData($tHandle, 1) If $CurrentPID <> 0 And $CurrentPID <> 4 Then If $PID Then If Not ($CurrentPID == $PID) Then ContinueLoop EndIf If $IgnoreSys Then If StringInStr($IgnoreList,$PID,2) Then ContinueLoop EndIf #region - Danger Zone - ;We need to avoid these attributes or we will freeze indefinately. If DllStructGetData($tHandle, 2) <> $FileObject Then ContinueLoop $Temporariis = DllStructGetData($tHandle, 6) If $Temporariis == 0x00120189 Then ContinueLoop If $Temporariis == 0x0012019f Then ContinueLoop If $Temporariis == 0x00100000 Then ContinueLoop #endregion - Danger Zone - $ResultCount += 1 ReDim $Result[$ResultCount + 1][2] $Result[$ResultCount - 1][0] = $CurrentPID $Result[$ResultCount - 1][1] = Ptr(DllStructGetData($tHandle, 4)) EndIf Next If Not $ResultCount Then Return SetError(1, 0, 0) EndIf Local $hSource Local $hObject Local $TempDat[1][4] Local $TempCount Local $LastPID Local $hTarget = DllCall($hKERNEL32, "handle", "GetCurrentProcess") If @error Then Return SetError(1, 0, 0) $hTarget = $hTarget[0] Local $struct = DllStructCreate("char[255];") Local $temp = DriveGetDrive("ALL") Local $drivesinfo[UBound($temp) - 1][2] For $i = 0 To UBound($drivesinfo) - 1 $drivesinfo[$i][0] = $temp[$i + 1] DllCall($hKERNEL32, "dword", "QueryDosDevice", "str", $drivesinfo[$i][0], "ptr", DllStructGetPtr($struct), "dword", 255) $drivesinfo[$i][1] = DllStructGetData($struct, 1) Next Local $PUBLIC_OBJECT_TYPE_INFORMATION = "ushort Length;" & _ "ushort MaximumLength;" & _ "ptr Buffer;" & _ ;UNICODE_STRING struct "wchar Reserved[260];" Local $poti = DllStructCreate($PUBLIC_OBJECT_TYPE_INFORMATION) Local $devicestr Local $Solid DllCall($hNTDLL, "int", "RtlAdjustPrivilege", "int", 20, "int", 1, "int", 0, "int*", 0) For $i = 1 To UBound($Result) - 1 If Not $LastPID Or $Result[$i][0] <> $LastPID Then If $LastPID Then DllCall($hKERNEL32, 'ptr', 'CloseHandle', 'ptr', $hSource) $hSource = DllCall($hKERNEL32, 'int', "OpenProcess", "int", 0x1F0FFF, "int", 0, "int", $Result[$i][0]) If @error Then ContinueLoop $hSource = $hSource[0] If Not $hSource Then ContinueLoop $LastPID = $Result[$i][0] EndIf $hObject = DllCall($hKERNEL32, _ "bool", "DuplicateHandle", _ "handle", $hSource, _ "handle", $Result[$i][1], _ "handle", $hTarget, _ "handle*", 0, _ "dword", 0, _ "bool", 0, _ "dword", 2 _ ) If @error Then ContinueLoop $hObject = $hObject[4] If Not @error Then $Solid = False DllCall($hNTDLL, "ulong", "NtQueryObject", "ptr", $hObject, "int", 1, "ptr", DllStructGetPtr($poti), "ulong", DllStructGetSize($poti), "ulong*", "") $devicestr = DllStructCreate("wchar[" & Ceiling(DllStructGetData($poti, "Length") / 2) & "];", DllStructGetData($poti, "buffer")) $devicestr = DllStructGetData($devicestr, 1) For $y = 0 To UBound($drivesinfo) - 1 If StringLeft($devicestr, StringLen($drivesinfo[$y][1])) = $drivesinfo[$y][1] Then $Solid = StringUpper($drivesinfo[$y][0]) & StringTrimLeft($devicestr, StringLen($drivesinfo[$y][1])) ExitLoop EndIf Next If $Solid Then $TempCount += 1 ReDim $TempDat[$TempCount + 1][3] $TempDat[$TempCount - 1][0] = $Result[$i][0];pid $TempDat[$TempCount - 1][1] = $Result[$i][1];hwnd $TempDat[$TempCount - 1][2] = $Solid EndIf DllCall($hKERNEL32, 'ptr', 'CloseHandle', 'ptr', $hObject) EndIf Next DllCall($hKERNEL32, 'ptr', 'CloseHandle', 'ptr', $hSource) If $TempCount Then ReDim $TempDat[$TempCount][3] EndIf Return SetError(0, 0, $TempDat) EndFunc ;==>_ListHwnds Edited March 29, 2012 by ApudAngelorum Link to comment Share on other sites More sharing options...
BrewManNH Posted March 29, 2012 Share Posted March 29, 2012 My understanding of this is, if you're opening a file and getting a file handle when you open it, don't you already know which file you opened? Why are you trying to get the filehandle -> Filename link, you should already have that. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
guinness Posted March 29, 2012 Share Posted March 29, 2012 My understanding of this is, if you're opening a file and getting a file handle when you open it, don't you already know which file you opened? Why are you trying to get the filehandle -> Filename link, you should already have that.True, ideally this information should ideally be stored in an Array (for example). UDF List: _AdapterConnections() • _AlwaysRun() • _AppMon() • _AppMonEx() • _ArrayFilter/_ArrayReduce • _BinaryBin() • _CheckMsgBox() • _CmdLineRaw() • _ContextMenu() • _ConvertLHWebColor()/_ConvertSHWebColor() • _DesktopDimensions() • _DisplayPassword() • _DotNet_Load()/_DotNet_Unload() • _Fibonacci() • _FileCompare() • _FileCompareContents() • _FileNameByHandle() • _FilePrefix/SRE() • _FindInFile() • _GetBackgroundColor()/_SetBackgroundColor() • _GetConrolID() • _GetCtrlClass() • _GetDirectoryFormat() • _GetDriveMediaType() • _GetFilename()/_GetFilenameExt() • _GetHardwareID() • _GetIP() • _GetIP_Country() • _GetOSLanguage() • _GetSavedSource() • _GetStringSize() • _GetSystemPaths() • _GetURLImage() • _GIFImage() • _GoogleWeather() • _GUICtrlCreateGroup() • _GUICtrlListBox_CreateArray() • _GUICtrlListView_CreateArray() • _GUICtrlListView_SaveCSV() • _GUICtrlListView_SaveHTML() • _GUICtrlListView_SaveTxt() • _GUICtrlListView_SaveXML() • _GUICtrlMenu_Recent() • _GUICtrlMenu_SetItemImage() • _GUICtrlTreeView_CreateArray() • _GUIDisable() • _GUIImageList_SetIconFromHandle() • _GUIRegisterMsg() • _GUISetIcon() • _Icon_Clear()/_Icon_Set() • _IdleTime() • _InetGet() • _InetGetGUI() • _InetGetProgress() • _IPDetails() • _IsFileOlder() • _IsGUID() • _IsHex() • _IsPalindrome() • _IsRegKey() • _IsStringRegExp() • _IsSystemDrive() • _IsUPX() • _IsValidType() • _IsWebColor() • _Language() • _Log() • _MicrosoftInternetConnectivity() • _MSDNDataType() • _PathFull/GetRelative/Split() • _PathSplitEx() • _PrintFromArray() • _ProgressSetMarquee() • _ReDim() • _RockPaperScissors()/_RockPaperScissorsLizardSpock() • _ScrollingCredits • _SelfDelete() • _SelfRename() • _SelfUpdate() • _SendTo() • _ShellAll() • _ShellFile() • _ShellFolder() • _SingletonHWID() • _SingletonPID() • _Startup() • _StringCompact() • _StringIsValid() • _StringRegExpMetaCharacters() • _StringReplaceWholeWord() • _StringStripChars() • _Temperature() • _TrialPeriod() • _UKToUSDate()/_USToUKDate() • _WinAPI_Create_CTL_CODE() • _WinAPI_CreateGUID() • _WMIDateStringToDate()/_DateToWMIDateString() • Au3 script parsing • AutoIt Search • AutoIt3 Portable • AutoIt3WrapperToPragma • AutoItWinGetTitle()/AutoItWinSetTitle() • Coding • DirToHTML5 • FileInstallr • FileReadLastChars() • GeoIP database • GUI - Only Close Button • GUI Examples • GUICtrlDeleteImage() • GUICtrlGetBkColor() • GUICtrlGetStyle() • GUIEvents • GUIGetBkColor() • Int_Parse() & Int_TryParse() • IsISBN() • LockFile() • Mapping CtrlIDs • OOP in AutoIt • ParseHeadersToSciTE() • PasswordValid • PasteBin • Posts Per Day • PreExpand • Protect Globals • Queue() • Resource Update • ResourcesEx • SciTE Jump • Settings INI • SHELLHOOK • Shunting-Yard • Signature Creator • Stack() • Stopwatch() • StringAddLF()/StringStripLF() • StringEOLToCRLF() • VSCROLL • WM_COPYDATA • More Examples... Updated: 22/04/2018 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