Jump to content
View in the app

A better way to browse. Learn more.

Tuts 4 You

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[delphi 7] How To Get Processid From Filename?

Featured Replies

Posted

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!!

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

  • Author

can you write an example code?

search for JCL delphi package, its simple then.

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

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

Create an account or sign in to comment

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.