|
-
Nov 20th, 2011, 03:41 PM
#1
find path of running process
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?
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 20th, 2011, 07:54 PM
#2
Addicted Member
Re: find path of running process
Check Out GetProcessImageFileName API to get the device path, then you have to convert the device path to a windows file path, have fun!
All men have an inherent right to life, the right to self determination including freedom from forced or compulsory labour, a right to hold opinions and the freedom of expression, and the right to a fair trial and freedom from torture. Be aware that these rights are universal and inalienable (cannot be given, taken or otherwise transferred or removed) although you do risk losing the aforementioned rights should you fail to uphold them e.g Charles Taylor; United Nations sources: http://www.un.org/en/documents/udhr/, http://www.ohchr.org/EN/Professional...ages/CCPR.aspx. Also Charles I was beheaded on the 30th of January of 1649 for trying to replace parliamentary democracy with an absolute monarchy, the same should happen to Dr Phil and Stephen Fry; source: http://www.vbforums.com/showthread.p...ute-Monarchism.
The plural of sun is stars you Catholic turkeys.
-
Nov 21st, 2011, 06:01 AM
#3
Re: find path of running process
thanks, i got that working now, but i cheated converting the device path
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 21st, 2011, 10:37 AM
#4
Re: find path of running process
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
-
Nov 21st, 2011, 03:16 PM
#5
Re: find path of running process
This may be of some interest;
this certainly works too
damn, too many choices now
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Nov 21st, 2011, 03:23 PM
#6
Re: find path of running process
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|