i have code that can loop through all running processes, match the name of the file and kill the process, but i want to find the path of the processes' exe file, any code sample to do this please?
Printable View
i have code that can loop through all running processes, match the name of the file and kill the process, but i want to find the path of the processes' exe file, any code sample to do this please?
Check Out GetProcessImageFileName API to get the device path, then you have to convert the device path to a windows file path, have fun!
thanks, i got that working now, but i cheated converting the device path
This may be of some interest;
Code:Private Const PROCESS_QUERY_INFORMATION = &H400&
Private Const PROCESS_VM_READ = &H10&
Private Const MAX_PATH = 260&
Private Declare Function GetModuleFileNameEx Lib "psapi" Alias "GetModuleFileNameExA" _
(ByVal hProcess As Long, ByVal hModule As Long, ByVal lpFilename As String, ByVal nSize As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" _
(ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Sub CloseHandle Lib "kernel32" (ByVal hObject As Long)
'returns the full path of a process identified by Pid.
Private Function GetPathFromPid(ByVal Pid As Long) As String
Dim hProcess As Long, s As String * MAX_PATH
hProcess = OpenProcess(PROCESS_QUERY_INFORMATION Or PROCESS_VM_READ, 0, Pid)
GetModuleFileNameEx hProcess, 0, s, MAX_PATH 'this call crashes under Win 95, 98 and probably NT4 and ME
CloseHandle hProcess
GetPathFromPid = Left$(s, InStr(s, vbNullChar) - 1)
End Function
this certainly works tooQuote:
This may be of some interest;
damn, too many choices now
To help make your mind up see the Remarks in http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx