as the subject says, i am wanting to find the path of an exe that is running on the same machine. searching through the pb docs and the forum i was unable to find a solution. would anyone be able to answer my question(hopefully a snippet) or point me in the right direction.
Thanks for your time.
Edit: Note this is for windows
how to find the path of another running process
how to find the path of another running process
Last edited by Suirad on Tue Jun 29, 2010 6:18 am, edited 1 time in total.
Re: how to find the path of another running process
would you be able to write your question in the board-standardformat?Suirad wrote:would anyone be able to answer my question
i hope nobody will answer at such kind of 'importend' questions and a mod will litter this topic
sorry for my bad english
Re: how to find the path of another running process
well sorry, i didnt know it was frowned upon to add a bit of color to my posts
Re: how to find the path of another running process
When you're in someone else's house, you abide by their rules.
Re: how to find the path of another running process
Well that's fine and dandy if the rules are clearly stated.Mr Coder wrote:When you're in someone else's house, you abide by their rules.
But that's off topic and already dealt with
-
- Enthusiast
- Posts: 107
- Joined: Thu May 06, 2010 11:36 pm
Re: how to find the path of another running process
Hello,
you did not tell us what information you have about the process. I assume that you know the PID of it, so here is the unofficial way to get the Path of an Executable if you know the PID:
Example usage:
For more Information, have a look at: http://www.purebasic.fr/english/viewtop ... 12&t=42608
DarkPlayer
you did not tell us what information you have about the process. I assume that you know the PID of it, so here is the unofficial way to get the Path of an Executable if you know the PID:
Code: Select all
Structure UNICODE_STRING
Length.w
MaxiumLength.w
*Buffer
EndStructure
Prototype.i GetVolumePathNameW(lpszFileName.p-unicode, *lpszVolumePathName, cchBufferLength.i)
Prototype.i GetVolumePathNameA(lpszFileName.p-ascii, *lpszVolumePathName, cchBufferLength.i)
CompilerIf #PB_Compiler_Unicode
Global GetVolumePathName.GetVolumePathNameW
CompilerElse
Global GetVolumePathName.GetVolumePathNameA
CompilerEndIf
#ProcessImageFileName = 27
Procedure FindStringIndex(Text.s, FindString.s, Index.i)
Protected Position = 0
Protected i.i
For i = 1 To Index
Position = FindString(Text, FindString,Position+1)
If Position = 0
ProcedureReturn 0
EndIf
Next
ProcedureReturn Position
EndProcedure
Procedure GetPathFromPID_Init()
Library = OpenLibrary(#PB_Any,"kernel32.dll")
If Library
CompilerIf #PB_Compiler_Unicode
GetVolumePathName = GetFunction(Library,"GetVolumePathNameW")
CompilerElse
GetVolumePathName = GetFunction(Library,"GetVolumePathNameA")
CompilerEndIf
ProcedureReturn #True
EndIf
EndProcedure
Procedure.s GetPathFromPID(PID.i)
Protected HProcess.i
Protected *Memory.UNICODE_STRING
Protected Name.s = ""
Protected Size.s
Protected Position.i
Protected Library.i
If PID = 4 : ProcedureReturn "SYSTEM" : EndIf
*Memory = AllocateMemory(2*#MAX_PATH)
If *Memory
HProcess = OpenProcess_(#PROCESS_QUERY_INFORMATION,0,PID)
If HProcess
If ZwQueryInformationProcess_(HProcess ,#ProcessImageFileName,*Memory,2*#MAX_PATH,0) = 0
Name = PeekS(*Memory\Buffer,*Memory\Length,#PB_Unicode)
Position = FindStringIndex(Name,"\",3)
If Position
Protected DeviceString.s = Space(128)
If GetVolumePathName(Name,@DeviceString,128)
Name = DeviceString + Mid(Name,Position+1)
EndIf
EndIf
EndIf
CloseHandle_(HProcess)
EndIf
FreeMemory(*Memory)
EndIf
ProcedureReturn Name
EndProcedure
Code: Select all
If GetPathFromPID_Init()
Debug GetPathFromPID(...)
EndIf
DarkPlayer
My blog: http://fds-team.de/cms/
Re: how to find the path of another running process
thank you, that was exactly what i was looking for