Jump to content
Tuts 4 You
Sign in to follow this  
V65j

[delphi 7] How To Get Processid From Filename?

Recommended Posts

V65j

hi friends

Please help me for get ProcessID From File name

i have a process . this process hase not caption and i must get this process id .

!!sorry for my Poor English!!

Share this post


Link to post
zako

Are you talking programmatically or not?, CreateToolhelp32Snapshot and associated functions Process32First/Process32Next is one way if not any process viewer will display it.

Edited by zako (see edit history)

Share this post


Link to post
V65j

can you write an example code?

Share this post


Link to post
ChupaChu

search for JCL delphi package, its simple then.

Share this post


Link to post
Departure

here is working example

http://www.delphipages.com/threads/thread.cfm?ID=184341&G=184250

This get the handel of the process but it first gets its process ID from the exe file name, So after reading this you should'nt have any problems

Share this post


Link to post
ante0

See if this function does it for you...

Function EnumThreadProc( wnd: HWND; Var appHwnd: HWND ): LongBool; 
stdcall;
Var
buf: array [0..128] of Char;
Begin
Result := LongBool(1);
if GetClassname( wnd, buf, sizeof(buf)) > 0 then
If StrComp( buf, 'TApplication' ) = 0 Then Begin
appHwnd := Wnd;
Result := False;
End; { If }
End;Function FindApplicationWindow( forThreadID: DWORD ): HWND;
Begin
Result := 0;
EnumThreadWindows( forThreadID, @EnumThreadProc, lparam(@result));
End;
Function ProcessIDFromAppname32( appname: String ): DWORD;
{ Take only the application filename, not full path! }
Var
snapshot: THandle;
processEntry : TProcessEntry32;
Begin
Result := 0;
appName := UpperCase( appname );
snapshot := CreateToolhelp32Snapshot(
TH32CS_SNAPPROCESS,
0 );
If snapshot <> 0 Then
try
processEntry.dwSize := Sizeof( processEntry );
If Process32First( snapshot, processEntry ) Then
Repeat
If Pos(appname,
UpperCase(ExtractFilename(
StrPas(processEntry.szExeFile)))) > 0
Then Begin
Result:= processEntry.th32ProcessID;
Break;
End; { If }
Until not Process32Next( snapshot, processEntry );
finally
CloseHandle( snapshot );
End; { try }
End;
Edited by ante0 (see edit history)

Share this post


Link to post

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×
×
  • Create New...