Helomotorola Posted September 14, 2007 Share Posted September 14, 2007 Get full path of a file from title windows expandcollapse popupOption Explicit Const PROCESS_QUERY_INFORMATION = 1024 Const PROCESS_VM_READ = 16 Const MAX_PATH As Integer = 260 Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Declare Function OpenProcess Lib "Kernel32.dll" (ByVal dwDesiredAccessas As Long, ByVal bInheritHandle As Long, ByVal dwProcId As Long) As Long Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long Private Declare Function EnumProcessModules Lib "PSAPI.DLL" (ByVal hProcess As Long, ByRef lphModule As Long, ByVal cb As Long, ByRef cbNeeded As Long) As Long Private Declare Function GetModuleFileNameEx Lib "PSAPI.DLL" Alias "GetModuleFileNameExA" (ByVal hProcess As Long, ByVal hModule As Long, ByVal ModuleName As String, ByVal nSize As Long) As Long Private Sub Command1_Click() Dim Ret As String Dim whwnd As Long Dim hMod As Long Dim theProcess As Long Dim lngCBSize2 As Long Dim lngModules(1 To 1) As Long Dim lngReturn As Long Dim strModuleName As String Dim lngSize As Long Dim strProcessName As String Ret = InputBox("Enter windows title:") If Ret = "" Then Exit Sub whwnd = FindWindow(vbNullString, Ret) If whwnd <> 0 Then hMod = GetWindowThreadProcessId(whwnd, theProcess) If hMod <> 0 Then 'Get a handle to the Process and Open Dim lngHwndProcess As Long lngHwndProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, theProcess) If lngHwndProcess <> 0 Then 'Get an array of the module handles for the specified process lngReturn = EnumProcessModules(lngHwndProcess, lngModules(1), 1, lngCBSize2) 'If the Module Array is retrieved, Get the ModuleFileName If lngReturn <> 0 Then 'Buffer with spaces first to allocate memory for byte array strModuleName = Space(MAX_PATH) 'Must be set prior to calling API lngSize = 500 'Get Process Name lngReturn = GetModuleFileNameEx(lngHwndProcess, lngModules(1), strModuleName, lngSize) If lngReturn > 0 Then 'Remove trailing spaces strProcessName = Left(strModuleName, lngReturn) End If End If End If 'Close the handle to this process lngReturn = CloseHandle(lngHwndProcess) End If'process finded End If'window finded If Len(strProcessName) > 0 Then MsgBox "Found: " & strProcessName End If End Sub Thank Link to comment Share on other sites More sharing options...
Sardith Posted September 14, 2007 Share Posted September 14, 2007 (edited) Something like this. ;Gets directory with supplied handle Func _WinGetPath($hWnd="") $hWnd = WinGetHandle($hWnd) $PID = WinGetProcess($hWnd) $colItems = "" $objWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Process WHERE ProcessId = " & $PID, "WQL", _ 0x10 + 0x20) If IsObj($colItems) Then For $objItem In $colItems If $objItem.ExecutablePath Then Return $objItem.ExecutablePath Next EndIf EndFunc Edited September 14, 2007 by Sardith [font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font] Link to comment Share on other sites More sharing options...
Sardith Posted September 14, 2007 Share Posted September 14, 2007 Little edit. [font="Verdana"]Valik:Get it straight - I'm not here to say please, I'm here to help - if my help's not appreciated then lotsa luck, gentlemen.[/font] Link to comment Share on other sites More sharing options...
Helomotorola Posted September 14, 2007 Author Share Posted September 14, 2007 Thank 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