<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; AHK: Получение пути открытого файла]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=12454</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=12454&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «AHK: Получение пути открытого файла».]]></description>
		<lastBuildDate>Sat, 18 Feb 2017 23:32:58 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112824#p112824</link>
			<description><![CDATA[<p>Парсите ваш список по алгоритму из последнего кода:<br /></p><div class="codebox"><pre><code>      if !DllCall(&quot;shlwapi\PathIsDirectory&quot;, Str, FilePath)
      {
         FinalPath := FilePath
         break
      }
      If (FinalPath = &quot;&quot;)
         FinalPath := FilePath</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sat, 18 Feb 2017 23:32:58 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112824#p112824</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112821#p112821</link>
			<description><![CDATA[<p>Так не всегда точно получается: часто не те пути выдаёт. Нельзя ли дополнить код, приводившийся <a href="http://forum.script-coding.com/viewtopic.php?pid=112800#p112800">выше</a>, он там выводит наиболее вероятные пути — нужно лишь дописать, чтобы результат по клавише с того кода, оставлял первый попавшийся файл, а если не найден, то первую попавшуюся директорию. То есть, по клавише F5 над любым процессом там иногда выводится несколько наиболее вероятных путей-строк, а надо из этих строк оставлять первый файл в списке, либо если таковой не был найден — первую папку в списке.</p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Sat, 18 Feb 2017 23:19:14 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112821#p112821</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112819#p112819</link>
			<description><![CDATA[<div class="codebox"><pre><code>process = wmplayer.exe
;videofiles = ,avi,mp4,mov    ; для поиска и файлов и папок заменить на ,avi,mp4,mov
NotInclude = ,C:\Windows,C:\Program Files (x86)

DetectHiddenWindows, on
SetBatchLines, -1
RunAsAdmin()
LoadLibraries()
EnablePrivilege()
If (A_Is64bitOS &amp;&amp; (A_PtrSize = 4))
   DllCall(&quot;Wow64DisableWow64FsRedirection&quot;, &quot;UInt*&quot;, OldValue)
WinGet, Pid, PID, ahk_exe %process%
msgbox  % GetAllFileHandleInfo(pid, videofiles, NotInclude)
return


GetAllFileHandleInfo(pid, videofiles, NotInclude)
{
   Static hCurrentProc := DllCall(&quot;GetCurrentProcess&quot;, &quot;UPtr&quot;)
   DataArray := []
   If !(SHI := QuerySystemHandleInformation())
   {
      MsgBox, 16, Error!, % &quot;Couldn&#039;t get SYSTEM_HANDLE_INFORMATION`nLast Error: &quot; . Format(&quot;0x{:08X}&quot;, ErrorLevel)
      Return False
   }
   HandleCount := SHI.Count
   Loop %HandleCount%
   {
      ; PROCESS_DUP_HANDLE = 0x40, PROCESS_QUERY_INFORMATION = 0x400
      If !(hProc := DllCall(&quot;OpenProcess&quot;, &quot;UInt&quot;, 0x0440, &quot;UInt&quot;, 0, &quot;UInt&quot;, SHI[A_Index, &quot;PID&quot;], &quot;UPtr&quot;))
         Continue
      ; DUPLICATE_SAME_ATTRIBUTES = 0x04 (4)
      If (SHI[A_Index].PID != pid) or !(hObject := DuplicateObject(hProc, hCurrentProc, SHI[A_Index, &quot;Handle&quot;], 4))
      {
         DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, hProc)
         Continue
      }
      If (OBI := QueryObjectBasicInformation(hObject))
      &amp;&amp; (OTI := QueryObjectTypeInformation(hObject))
      &amp;&amp; (OTI.Type = &quot;File&quot;)
      &amp;&amp; (DllCall(&quot;GetFileType&quot;, &quot;Ptr&quot;, hObject, &quot;UInt&quot;) = 1)
      &amp;&amp; (ONI := QueryObjectNameInformation(hObject))
      {
         ; VarSetCapacity(ProcFullPath, 520, 0)
         ; DllCall(&quot;QueryFullProcessImageName&quot;, &quot;Ptr&quot;, hProc, &quot;UInt&quot;, 0, &quot;Str&quot;, ProcFullPath, &quot;UIntP&quot;, sz := 260) ; NOT COMPATIBLE WITH WINDOWS XP
         FilePath := GetPathNameByHandle(hObject)
      }
      DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, hObject)
      DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, hProc)
      if FilePath in %NotInclude%
         Continue
      if !DllCall(&quot;shlwapi\PathIsDirectory&quot;, Str, FilePath)
      {
         FinalPath := FilePath
         break
      }
      If (FinalPath = &quot;&quot;)
         FinalPath := FilePath
   }
   return FinalPath
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sat, 18 Feb 2017 22:42:01 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112819#p112819</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112818#p112818</link>
			<description><![CDATA[<p>Угу.</p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Sat, 18 Feb 2017 22:28:16 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112818#p112818</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112817#p112817</link>
			<description><![CDATA[<p>Выводить первый попавшийся файл, а если такого нету, то первую попавшиесю директорию?</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sat, 18 Feb 2017 22:12:20 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112817#p112817</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112816#p112816</link>
			<description><![CDATA[<p>Хотел бы по клавише получать путь либо к открытому в активной программе файлу, либо к папке, если файл не был залочен. Конечно, задача осложняется из-за иногда множества левых путей в выводе.</p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Sat, 18 Feb 2017 21:57:12 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112816#p112816</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112813#p112813</link>
			<description><![CDATA[<p>А что вы хотите в итоге получить?</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sat, 18 Feb 2017 21:01:40 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112813#p112813</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112800#p112800</link>
			<description><![CDATA[<p>Следующий код настраивался для работы по клавише над активным окном — без указания процесса и расширений. Нужна доработка, чтобы сначала производился вывод первого файла, а потом, если он не был найден — первой папки (иначе, если процесс содержит и папку и файл, то сначала выводилась папка). Судя по всему, первые файлы и папки, если не находятся на C:\, оказываются искомыми.<br /></p><div class="codebox"><pre><code>
F5::
DetectHiddenWindows, on
SetBatchLines, -1
RunAsAdmin()
LoadLibraries()
EnablePrivilege()
If (A_Is64bitOS &amp;&amp; (A_PtrSize = 4))
   DllCall(&quot;Wow64DisableWow64FsRedirection&quot;, &quot;UInt*&quot;, OldValue)

Exe_Name := GetExecutableName()

process = %Exe_Name%
; для поиска и файлов и папок заменить на ,avi,mp4,mov
videofiles = ,avi,mp4,mov,djvu,pdf,txt
NotInclude = C:\Windows,C:\Program Files (x86),C:\Windows\System32,C:\Program Files

WinGet, Pid, PID, ahk_exe %process%
GetAllFileHandleInfo(pid, videofiles, NotInclude)
FileRead, All, %A_Temp%\Log.txt
FileDelete, %A_Temp%\Log.txt

All := RegExReplace(All, &quot;s)(.*)(\w:\\.*)&quot;, &quot;$1`n$2&quot;) ; все пути с новой строки
StringReplace, All, All, C:\Windows, C-\Windows,All
StringReplace, All, All, C:\Program, C-\Program,All
StringReplace, All, All, C:\Users,   C-\Users,All
StringReplace, All, All, C:\Temp,    C-\Temp,All
;All := RegExReplace(All, &quot;m`a)\w-.+&quot;)  ; удал. начинающиеся на \w-\
All := RegExReplace(All, &quot;\R+\s*&quot;, &quot;&quot;) ; удал. пустые строки

MsgBox, % All
return

GetExecutableName() {  ; GetExecutableName := GetExecutableName()
  WinGet, PID_Target, PID, % &quot;ahk_id &quot; WinExist(&quot;A&quot;)
  ComObjGet(&quot;winmgmts:&quot;).ExecQuery(&quot;Select * from Win32_Process WHERE ProcessId = &quot;
  . PID_Target)._NewEnum.next(x)
  GetExecutableName := % x.Name ;% или Caption
  Return %GetExecutableName%
}

GetAllFileHandleInfo(pid, videofiles, NotInclude) {
   Static hCurrentProc := DllCall(&quot;GetCurrentProcess&quot;, &quot;UPtr&quot;)
   DataArray := []
   If !(SHI := QuerySystemHandleInformation()) {
      MsgBox, 16, Error!, % &quot;Couldn&#039;t get SYSTEM_HANDLE_INFORMATION`nLast Error: &quot; . Format(&quot;0x{:08X}&quot;, ErrorLevel)
      Return False
   }
   HandleCount := SHI.Count
   Loop %HandleCount% {
      ; PROCESS_DUP_HANDLE = 0x40, PROCESS_QUERY_INFORMATION = 0x400
      If !(hProc := DllCall(&quot;OpenProcess&quot;, &quot;UInt&quot;, 0x0440, &quot;UInt&quot;, 0, &quot;UInt&quot;, SHI[A_Index, &quot;PID&quot;], &quot;UPtr&quot;))
            Continue
      if (SHI[A_Index].PID != pid)
            Continue
      ; DUPLICATE_SAME_ATTRIBUTES = 0x04 (4)
      If !(hObject := DuplicateObject(hProc, hCurrentProc, SHI[A_Index, &quot;Handle&quot;], 4)) {
            DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, hProc)
            Continue
      }
      If (OBI := QueryObjectBasicInformation(hObject))
      &amp;&amp; (OTI := QueryObjectTypeInformation(hObject))
      &amp;&amp; (OTI.Type = &quot;File&quot;)
      &amp;&amp; (DllCall(&quot;GetFileType&quot;, &quot;Ptr&quot;, hObject, &quot;UInt&quot;) = 1)
      &amp;&amp; (ONI := QueryObjectNameInformation(hObject)) {
            ; VarSetCapacity(ProcFullPath, 520, 0)
            ; DllCall(&quot;QueryFullProcessImageName&quot;, &quot;Ptr&quot;, hProc, &quot;UInt&quot;, 0, &quot;Str&quot;, ProcFullPath, &quot;UIntP&quot;, sz := 260) ; NOT COMPATIBLE WITH WINDOWS XP

            FilePath := GetPathNameByHandle(hObject)







            fileappend, %FilePath%`t, %A_Temp%\Log.txt
/*
            if FilePath in %NotInclude%
               Continue
            SplitPath,FilePath,,,ext
            if ext in %videofiles%
            {
               DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, hObject)
               DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, hProc)
               Return FilePath
            }
*/







      }
   }
}



LoadLibraries() {
   DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;Advapi32.dll&quot;, &quot;UPtr&quot;)
   DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;Ntdll.dll&quot;, &quot;UPtr&quot;)
   DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;Shell32.dll&quot;, &quot;UPtr&quot;)
   DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;Iphlpapi.dll&quot;, &quot;UPtr&quot;)
   DllCall(&quot;LoadLibrary&quot;, &quot;Str&quot;, &quot;psapi.dll&quot;, &quot;UPtr&quot;)
}

; ==================================================================================================================================
; General functions that can simply be used in other scripts =======================================================================
; ==================================================================================================================================
GetProcessFilePath(hProcess) {
   nSize := VarSetCapacity(lpFilename, 260 * (A_IsUnicode ? 2 : 1), 0)
   If !(DllCall(&quot;GetModuleFileNameEx&quot;, &quot;Ptr&quot;, hProcess, &quot;Ptr&quot;, 0, &quot;Str&quot;, lpFilename, &quot;UInt&quot;, nSize))
      If !(DllCall(&quot;psapi.dll\GetModuleFileNameEx&quot;, &quot;Ptr&quot;, hProcess, &quot;Ptr&quot;, 0, &quot;Str&quot;, lpFilename, &quot;UInt&quot;, nSize))
         Return (ErrorLevel := 2) &amp; 0
   Return lpFilename
}
; ==================================================================================================================================
GetProcessFilePathByPID(PID) {
   If !(hProcess := DllCall(&quot;OpenProcess&quot;, &quot;UInt&quot;, 0x10|0x400, &quot;Int&quot;, 0, &quot;UInt&quot;, PID, &quot;UPtr&quot;))
      Return (ErrorLevel := 1) &amp; 0
   lpFilename := GetProcessFilePath(hProcess)
   DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, hProcess)
   Return lpFilename
}
; ==================================================================================================================================
GetExtendedTcpTable() {
   ; https://msdn.microsoft.com/en-us/library/aa365928.aspx
   Static AF_INET := 2, TCP_TABLE_OWNER_PID_ALL := 5
   DllCall(&quot;Iphlpapi.dll\GetExtendedTcpTable&quot;, &quot;Ptr&quot;, 0, &quot;UInt*&quot;, pdwSize, &quot;Int&quot;, 0, &quot;UInt&quot;, AF_INET, &quot;UInt&quot;, TCP_TABLE_OWNER_PID_ALL, &quot;UInt&quot;, 0)
   VarSetCapacity(pTcpTable, pdwSize, 0)
   If (DllCall(&quot;Iphlpapi.dll\GetExtendedTcpTable&quot;, &quot;Ptr&quot;, &amp;pTcpTable, &quot;UInt*&quot;, pdwSize, &quot;Int&quot;, 0, &quot;UInt&quot;, AF_INET, &quot;UInt&quot;, TCP_TABLE_OWNER_PID_ALL, &quot;UInt&quot;, 0) != 0)
      Return (ErrorLevel := 1) &amp; 0

   Offset := 0, TcpTable := []
   Loop % NumGet(pTcpTable, &quot;UInt&quot;) {
      TcpTable[A_Index, &quot;State&quot;] := NumGet(&amp;pTcpTable + (Offset+=4), &quot;UInt&quot;)
      TcpTable[A_Index, &quot;LocalAddr&quot;] := NumGet(&amp;pTcpTable + (Offset+=4), &quot;UInt&quot;)
      TcpTable[A_Index, &quot;LocalPort&quot;] := NumGet(&amp;pTcpTable + (Offset+=4), &quot;UInt&quot;)
      TcpTable[A_Index, &quot;RemoteAddr&quot;] := NumGet(&amp;pTcpTable + (Offset+=4), &quot;UInt&quot;)
      TcpTable[A_Index, &quot;RemotePort&quot;] := NumGet(&amp;pTcpTable + (Offset+=4), &quot;UInt&quot;)
      TcpTable[A_Index, &quot;OwningPid&quot;] := NumGet(&amp;pTcpTable + (Offset+=4), &quot;UInt&quot;)
   }
   Return TcpTable
}
; ==================================================================================================================================
;SetScrollInfo(hwnd, ScrollInfoObj, fnBar:=1, fRedraw:=True) {
;    ; NOT SUPPORTED ON WINDOWS XP
;    ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb787583%28v=vs.85%29.aspx
;    VarSetCapacity(SCROLLINFO, ScrollInfoObj.Size, 0)
;    NumPut(ScrollInfoObj.Size, SCROLLINFO, 0, &quot;UInt&quot;) 
;    NumPut(ScrollInfoObj.Mask, SCROLLINFO, 4, &quot;UInt&quot;)
;    NumPut(ScrollInfoObj.Min, SCROLLINFO, 8, &quot;Int&quot;)
;    NumPut(ScrollInfoObj.Max, SCROLLINFO, 12, &quot;Int&quot;)
;    NumPut(ScrollInfoObj.Page, SCROLLINFO, 16, &quot;UInt&quot;)
;    NumPut(ScrollInfoObj.Pos, SCROLLINFO, 20, &quot;Int&quot;)
;    NumPut(ScrollInfoObj.TrackPos, SCROLLINFO, 24, &quot;Int&quot;)
;    Return DllCall(&quot;User32.dll\SetScrollInfo&quot;, &quot;Ptr&quot;, hwnd, &quot;Int&quot;, fnBar, &quot;Ptr&quot;, &amp;SCROLLINFO)
;}
;; ==================================================================================================================================
;GetScrollInfo(hwnd, fnBar:=1) {
;    ; NOT SUPPORTED ON WINDOWS XP
;    ; https://msdn.microsoft.com/en-us/library/windows/desktop/bb787583%28v=vs.85%29.aspx
;    VarSetCapacity(SCROLLINFO, 28, 0)
;    NumPut(28, SCROLLINFO, 0, &quot;UInt&quot;) 
;    NumPut(0x1F, SCROLLINFO, 4, &quot;UInt&quot;) ; SIF_ALL
;    If !DllCall(&quot;User32.dll\GetScrollInfo&quot;, &quot;Ptr&quot;, hwnd, &quot;Int&quot;, fnBar, &quot;Ptr&quot;, &amp;SCROLLINFO)
;        Return False
;
;    ScrollInfoObj := {}
;    ScrollInfoObj.Size := NumGet(SCROLLINFO, 0, &quot;UInt&quot;)
;    ScrollInfoObj.Mask := NumGet(SCROLLINFO, 4, &quot;UInt&quot;)
;    ScrollInfoObj.Min := NumGet(SCROLLINFO, 8, &quot;Int&quot;)
;    ScrollInfoObj.Max := NumGet(SCROLLINFO, 12, &quot;Int&quot;)
;    ScrollInfoObj.Page := NumGet(SCROLLINFO, 16, &quot;UInt&quot;)
;    ScrollInfoObj.Pos  := NumGet(SCROLLINFO, 20, &quot;Int&quot;)
;    ScrollInfoObj.TrackPos := NumGet(SCROLLINFO, 24, &quot;Int&quot;)
;
;    Return ScrollInfoObj
;}
; ==================================================================================================================================
OpenProcess(PID := 0, Privileges := -1) {
   Return DllCall(&quot;OpenProcess&quot;, &quot;Uint&quot;, (Privileges = -1) ? 0x1F0FFF : Privileges, &quot;Uint&quot;, False, &quot;Uint&quot;, PID ? PID : DllCall(&quot;GetCurrentProcessId&quot;))
} 

; ==================================================================================================================================
GetIconByPath(Path, FileExists:=&quot;&quot;) { ; fully qualified file path, result of FileExist on Path (optional)
   ; SHGetFileInfo  -&gt; http://msdn.microsoft.com/en-us/library/bb762179(v=vs.85).aspx
   ; FIXME:
   ;     For 32-bit AHK File System Redirection is automatically enabled when running on a 64-bit OS. 
   ;     So files which exist in Sytem32 (64-bit) but not in SysWOW64 (32-bit) won&#039;t be found. 
   ;     Also, all files which exist in both directories might address the wrong file. 
   ;     So the file redirection must be disabled in this case (A_Is64bitOS &amp;&amp; (A_PtrSize = 4)).
   Static AW := A_IsUnicode ? &quot;W&quot; : &quot;A&quot;
   Static cbSFI := A_PtrSize + 8 + (340 &lt;&lt; !!A_IsUnicode)
   Static IconType := 2
   FileExists := FileExists ? FileExists : FileExist(Path)
   If (FileExists) {
      SplitPath, Path, , , FileExt
      If (InStr(FileExists, &quot;D&quot;) || FileExt = &quot;exe&quot; || FileExt = &quot;ico&quot; || FileExt = &quot;&quot;) {
         pszPath := Path
         dwFileAttributes := 0x00
         uFlags := 0x0101
      } Else {
         pszPath := &quot;.&quot; FileExt
         dwFileAttributes := 0x80
         uFlags := 0x0111
      }
   } Else ; If the file is deleted reutrn an appropriate icon. 
      Return LoadPicture(A_WinDir &quot;\System32\imageres.dll&quot;, &quot;Icon85 w16 h16&quot;, IconType) ; TODO: find a way to retrieve the icon just once and return it everytime it is needed
      ;TODO: maybe remove this because other scripts might not want to get this icon when the file is not existent

   VarSetCapacity(SFI, cbSFI, 0) ; SHFILEINFO
   DllCall(&quot;Shell32.dll\SHGetFileInfo&quot; . AW, &quot;Str&quot;, pszPath, &quot;UInt&quot;, dwFileAttributes, &quot;Ptr&quot;, &amp;SFI, &quot;UInt&quot;, cbSFI, &quot;UInt&quot;, uFlags, &quot;UInt&quot;)
   Return NumGet(SFI, 0, &quot;UPtr&quot;)
}
; ==================================================================================================================================
GetPathNameByHandle(hFile) {
   VarSetCapacity(FilePath, 4096, 0)
   DllCall(&quot;GetFinalPathNameByHandle&quot;, &quot;Ptr&quot;, hFile, &quot;Str&quot;, FilePath, &quot;UInt&quot;, 2048, &quot;UInt&quot;, 0, &quot;UInt&quot;)
   Return SubStr(FilePath, 1, 4) = &quot;\\?\&quot; ? SubStr(FilePath, 5) : FilePath
}
; ==================================================================================================================================
DuplicateObject(hProc, hCurrentProc, Handle, Options) {
   ; PROCESS_DUP_HANDLE = 0x40, PROCESS_QUERY_INFORMATION = 0x400, DUPLICATE_SAME_ATTRIBUTES = 0x04 (4)
   Status := DllCall(&quot;Ntdll.dll\ZwDuplicateObject&quot;, &quot;Ptr&quot;, hProc
                                    , &quot;Ptr&quot;, Handle
                                    , &quot;Ptr&quot;, hCurrentProc
                                    , &quot;PtrP&quot;, hObject
                                    , &quot;UInt&quot;, 0
                                    , &quot;UInt&quot;, 0
                                    , &quot;UInt&quot;, Options
                                    , &quot;UInt&quot;)
   Return (Status) ? !(ErrorLevel := Status) : hObject
}
; ==================================================================================================================================
QueryObjectBasicInformation(hObject) {
   ; ObjectBasicInformation = 0, STATUS_INFO_LENGTH_MISMATCH = 0xC0000004
   Static Size := 56 ; size of OBJECT_BASIC_INFORMATION
   VarSetCapacity(OBI, Size, 0)
   Status := DllCall(&quot;Ntdll.dll\ZwQueryObject&quot;, &quot;Ptr&quot;, hObject, &quot;UInt&quot;, 0, &quot;Ptr&quot;, &amp;OBI, &quot;UInt&quot;, Size, &quot;UIntP&quot;, L, &quot;UInt&quot;)
   If (Status = 0xC0000004) {
      VarSetCapacity(OBI, L)
      Status := DllCall(&quot;Ntdll.dll\ZwQueryObject&quot;, &quot;Ptr&quot;, hObject, &quot;UInt&quot;, 0, &quot;Ptr&quot;, &amp;OBI, &quot;UInt&quot;, L, &quot;Ptr&quot;, 0, &quot;UInt&quot;)
   }
   Return (Status) ? !(ErrorLevel := Status)
               : {Attr: NumGet(OBI, 0, &quot;UInt&quot;)
               , Access: NumGet(OBI, 4, &quot;UInt&quot;)
               , Handles: NumGet(OBI, 8, &quot;UInt&quot;)
               , Pointers: NumGet(OBI, 12, &quot;UInt&quot;)}
}
; ==================================================================================================================================
QueryObjectTypeInformation(hObject, Size := 4096) {
   ; ObjectTypeInformation = 2, STATUS_INFO_LENGTH_MISMATCH = 0xC0000004
   VarSetCapacity(OTI, Size, 0)
   Status := DllCall(&quot;Ntdll.dll\ZwQueryObject&quot;, &quot;Ptr&quot;, hObject, &quot;UInt&quot;, 2, &quot;Ptr&quot;, &amp;OTI, &quot;UInt&quot;, Size, &quot;UIntP&quot;, L, &quot;UInt&quot;)
   If (Status = 0xC0000004) {
      VarSetCapacity(OTI, L)
      Status := DllCall(&quot;Ntdll.dll\ZwQueryObject&quot;, &quot;Ptr&quot;, hObject, &quot;UInt&quot;, 2, &quot;Ptr&quot;, &amp;OTI, &quot;UInt&quot;, L, &quot;Ptr&quot;, 0, &quot;UInt&quot;)
   }
   Return (Status) ? !(ErrorLevel := Status)
               : {Type: StrGet(NumGet(OTI, A_PtrSize, &quot;UPtr&quot;), NumGet(OTI, 0, &quot;UShort&quot;) // 2, &quot;UTF-16&quot;)}
}
; ==================================================================================================================================
QueryObjectNameInformation(hobject, Size := 4096) {
   ; ObjectNameInformation = 1, STATUS_INFO_LENGTH_MISMATCH = 0xC0000004
   VarSetCapacity(ONI, Size, 0)
   Status := DllCall(&quot;Ntdll.dll\ZwQueryObject&quot;, &quot;Ptr&quot;, hObject, &quot;UInt&quot;, 1, &quot;Ptr&quot;, &amp;ONI, &quot;UInt&quot;, Size, &quot;UIntP&quot;, L, &quot;UInt&quot;)
   If (Status = 0xc0000004) {
      VarSetCapacity(ONI, L)
      Status := DllCall(&quot;Ntdll.dll\ZwQueryObject&quot;, &quot;Ptr&quot;, hObject, &quot;UInt&quot;, 1, &quot;Ptr&quot;, &amp;ONI, &quot;UInt&quot;, L, &quot;Ptr&quot;, 0, &quot;UInt&quot;)
   }
   Return (Status) ? !(ErrorLevel := Status)
               : {Name: StrGet(NumGet(ONI, A_PtrSize, &quot;UPtr&quot;), NumGet(ONI, 0, &quot;UShort&quot;) // 2, &quot;UTF-16&quot;)}
}
; ==================================================================================================================================
QuerySystemHandleInformation() {
   ; SystemHandleInformation = 16, STATUS_INFO_LENGTH_MISMATCH = 0xC0000004
   Static SizeSH := 8 + (A_PtrSize * 2)
   Static Size := A_PtrSize * 4096
   VarSetCapacity(SHI, Size)
   Status := DllCall(&quot;Ntdll.dll\NtQuerySystemInformation&quot;, &quot;UInt&quot;, 16, &quot;Ptr&quot;, &amp;SHI, &quot;UInt&quot;, Size, &quot;UIntP&quot;, L, &quot;UInt&quot;)
   While (Status = 0xc0000004) {
      VarSetCapacity(SHI, L)
      Status := DllCall(&quot;Ntdll.dll\NtQuerySystemInformation&quot;, &quot;UInt&quot;, 16, &quot;Ptr&quot;, &amp;SHI, &quot;UInt&quot;, L, &quot;UIntP&quot;, L, &quot;UInt&quot;)
   }
   If (Status)
      Return !(ErrorLevel := Status)
   HandleCount := NumGet(SHI, &quot;UInt&quot;)
   ObjSHI := {Count: HandleCount}
   Addr := &amp;SHI + A_PtrSize
   Loop, %HandleCount% {
      ObjSHI.Push({PID: NumGet(Addr + 0, &quot;UInt&quot;)
            , Type: NumGet(Addr + 4, &quot;UChar&quot;)
            , Flags: NumGet(Addr + 5, &quot;UChar&quot;)
            , Handle: NumGet(Addr + 6, &quot;UShort&quot;)
            , Addr: NumGet(Addr + 8, &quot;UPtr&quot;)
            , Access: NumGet(Addr + 8, A_PtrSize, &quot;UInt&quot;)})
      Addr += SizeSH
   }
   Return ObjSHI
}
; ==================================================================================================================================
EnablePrivilege(Name := &quot;SeDebugPrivilege&quot;) {
   hProc := DllCall(&quot;GetCurrentProcess&quot;, &quot;UPtr&quot;)
   If DllCall(&quot;Advapi32.dll\LookupPrivilegeValue&quot;, &quot;Ptr&quot;, 0, &quot;Str&quot;, Name, &quot;Int64P&quot;, LUID := 0, &quot;UInt&quot;)
   &amp;&amp; DllCall(&quot;Advapi32.dll\OpenProcessToken&quot;, &quot;Ptr&quot;, hProc, &quot;UInt&quot;, 32, &quot;PtrP&quot;, hToken := 0, &quot;UInt&quot;) { ; TOKEN_ADJUST_PRIVILEGES = 32
      VarSetCapacity(TP, 16, 0) ; TOKEN_PRIVILEGES
      , NumPut(1, TP, &quot;UInt&quot;)
      , NumPut(LUID, TP, 4, &quot;UInt64&quot;)
      , NumPut(2, TP, 12, &quot;UInt&quot;) ; SE_PRIVILEGE_ENABLED = 2
      , DllCall(&quot;Advapi32.dll\AdjustTokenPrivileges&quot;, &quot;Ptr&quot;, hToken, &quot;UInt&quot;, 0, &quot;Ptr&quot;, &amp;TP, &quot;UInt&quot;, 0, &quot;Ptr&quot;, 0, &quot;Ptr&quot;, 0, &quot;UInt&quot;)
   }
   LastError := A_LastError
   If (hToken)
      DllCall(&quot;CloseHandle&quot;, &quot;Ptr&quot;, hToken)
   Return !(ErrorLevel := LastError)
}
; ==================================================================================================================================
RunAsAdmin() {
   If !(A_IsAdmin) {
      Run % &quot;*RunAs &quot; . (A_IsCompiled ? &quot;&quot; : A_AhkPath . &quot; &quot;) . &quot;&quot;&quot;&quot; . A_ScriptFullPath . &quot;&quot;&quot;&quot;
      ExitApp
   }
}
</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Sat, 18 Feb 2017 19:11:36 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112800#p112800</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112776#p112776</link>
			<description><![CDATA[<p>Еще потребуется в не включаемые C:\Windows\System32 добавить — иногда тоже выводилась.</p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Sat, 18 Feb 2017 10:32:37 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112776#p112776</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112743#p112743</link>
			<description><![CDATA[<p>Добавил папки, которые не включаем в поиск, а то будет C:\Windows первой выходить.<br />Ну а вообще в коде куча всего непонятного, возможно для данной задачи и ненужного.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Fri, 17 Feb 2017 19:25:49 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112743#p112743</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112742#p112742</link>
			<description><![CDATA[<p>Благодарю!</p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Fri, 17 Feb 2017 19:16:16 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112742#p112742</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112741#p112741</link>
			<description><![CDATA[<div class="quotebox"><blockquote><p>Теперь он именно к процессу обращается?</p></blockquote></div><p>Нет, просто подтер ненужные действия.<br />Чтобы не исключать папки, нужно заменить на videofiles = ,avi,mp4,mov</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Fri, 17 Feb 2017 19:13:58 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112741#p112741</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112739#p112739</link>
			<description><![CDATA[<p>Это мечта, спасибо! Теперь он именно к процессу обращается? И можно ещё попросить обработку папок приделать — на случай, если файла не окажется?</p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Fri, 17 Feb 2017 18:57:39 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112739#p112739</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112738#p112738</link>
			<description><![CDATA[<p>Ускорил. <br />На ssd 1800 файлов - 420 милисекунд.</p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Fri, 17 Feb 2017 18:52:54 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112738#p112738</guid>
		</item>
		<item>
			<title><![CDATA[Re: AHK: Получение пути открытого файла]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=112737#p112737</link>
			<description><![CDATA[<p>У меня 1200 файлов не на SSD — перебирает чуть ли не пять секунд. Так и понял что всё перебирает, стоило бы переделать на более прицельную работу.</p>]]></description>
			<author><![CDATA[null@example.com (DD)]]></author>
			<pubDate>Fri, 17 Feb 2017 18:28:11 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=112737#p112737</guid>
		</item>
	</channel>
</rss>
