Board index » delphi » get the program name

get the program name

Hi

I'm making an audit program...   it writes a log file about the running
programs....

i get the window names with GetWindowText and Class name, ID with
GetClassLong....

but i don't know how to get the program name, or the executable name (like
winamp.exe...etc) like windows taskmanager....

PS: i need to solove this problem without PSAPI

Thank you very much
             Mickey

 

Re:get the program name


ParamStr(0) is the program name...

Quote
"mice007" <mice...@freemail.hu> wrote in message

news:9idp64$npe$1@namru.matavnet.hu...
Quote
> Hi

> I'm making an audit program...   it writes a log file about the running
> programs....

> i get the window names with GetWindowText and Class name, ID with
> GetClassLong....

> but i don't know how to get the program name, or the executable name (like
> winamp.exe...etc) like windows taskmanager....

> PS: i need to solove this problem without PSAPI

> Thank you very much
>              Mickey

Re:get the program name


Give this a try, this should work on 98/2000.
Once you get the window handle you can get the exe file it is associated
with.

//Code here

type GetWinFileNameA = function(hWnd : HWND; FileName : PChar; Length :
Integer):Integer;stdcall;

function GetFileNameFromWindow(hWnd : HWND):string;
var
hModule : Integer;
GetWinFileNameAProc : GetWinFileNameA;
Buffer : array[0..255] of Char;
begin
    hModule := LoadLibrary('USER32.DLL');
    @GetWinFileNameAProc := GetProcAddress(hModule,
'GetWindowModuleFileNameA');
    GetWinFileNameAProc(hWnd, Buffer, 255);
    Result := Buffer;
end;

Quote
"mice007" <mice...@freemail.hu> wrote in message

news:9idp64$npe$1@namru.matavnet.hu...
Quote
> Hi

> I'm making an audit program...   it writes a log file about the running
> programs....

> i get the window names with GetWindowText and Class name, ID with
> GetClassLong....

> but i don't know how to get the program name, or the executable name (like
> winamp.exe...etc) like windows taskmanager....

> PS: i need to solove this problem without PSAPI

> Thank you very much
>              Mickey

Re:get the program name


Why can't you use PSApi ? You just have to take check the windows version
and use TLHelp32 or PSApi accordingly.
The Jedi JCL (http://www.delphi-jedi.org/Jedi:CODELIBJCL) already contains a
routine that does this check for you and creates a list of running
applications.

"mice007" <mice...@freemail.hu> schreef in bericht
news:9idp64$npe$1@namru.matavnet.hu...

Quote
> Hi

> I'm making an audit program...   it writes a log file about the running
> programs....

> i get the window names with GetWindowText and Class name, ID with
> GetClassLong....

> but i don't know how to get the program name, or the executable name (like
> winamp.exe...etc) like windows taskmanager....

> PS: i need to solove this problem without PSAPI

> Thank you very much
>              Mickey

Re:get the program name


Try Application.ExeName.

Quote
"mice007" <mice...@freemail.hu> wrote in message

news:9idp64$npe$1@namru.matavnet.hu...
Quote
> Hi

> I'm making an audit program...   it writes a log file about the running
> programs....

> i get the window names with GetWindowText and Class name, ID with
> GetClassLong....

> but i don't know how to get the program name, or the executable name (like
> winamp.exe...etc) like windows taskmanager....

> PS: i need to solove this problem without PSAPI

> Thank you very much
>              Mickey

Re:get the program name


Use the CreateToolHelp32Snapshot function, look it up in Win32 help, it will
(along with a few other ToolHelp functions) allow you to get a complete
process list including executable names and paths as well as other useful
info like Process IDs and parent Process IDs

Quote
"Hai Vu" <haitua...@hotmail.com> wrote in message

news:vbFc7.1434$q46.122646@newsread2.prod.itd.earthlink.net...
Quote
> Try Application.ExeName.

> "mice007" <mice...@freemail.hu> wrote in message
> news:9idp64$npe$1@namru.matavnet.hu...
> > Hi

> > I'm making an audit program...   it writes a log file about the running
> > programs....

> > i get the window names with GetWindowText and Class name, ID with
> > GetClassLong....

> > but i don't know how to get the program name, or the executable name
(like
> > winamp.exe...etc) like windows taskmanager....

> > PS: i need to solove this problem without PSAPI

> > Thank you very much
> >              Mickey

Re:get the program name


Quote
On Mon, 13 Aug 2001, ntlWorld News wrote:
> Use the CreateToolHelp32Snapshot function, look it up in Win32 help, it will
> (along with a few other ToolHelp functions) allow you to get a complete
> process list including executable names and paths as well as other useful
> info like Process IDs and parent Process IDs

The toolhelp functions work in 95/98/ME and 2000 but not NT 4.

Erick

Quote

> "Hai Vu" <haitua...@hotmail.com> wrote in message
> news:vbFc7.1434$q46.122646@newsread2.prod.itd.earthlink.net...
> > Try Application.ExeName.

> > "mice007" <mice...@freemail.hu> wrote in message
> > news:9idp64$npe$1@namru.matavnet.hu...
> > > Hi

> > > I'm making an audit program...   it writes a log file about the running
> > > programs....

> > > i get the window names with GetWindowText and Class name, ID with
> > > GetClassLong....

> > > but i don't know how to get the program name, or the executable name
> (like
> > > winamp.exe...etc) like windows taskmanager....

> > > PS: i need to solove this problem without PSAPI

> > > Thank you very much
> > >              Mickey

Re:get the program name


That is why I suggested the use of both TLHelp32 and PSApi. The Jedi JCL
(http://www.delphi-jedi.org/Jedi:CODELIBJCL) already contains a
routine that does the platformtest and uses TLHelp32 or PSApi accordingly.

Quote
"Erick Engelke" <er...@engmail.uwaterloo.ca> wrote in message

news:Pine.GSO.4.05.10108141102070.5940-100000@engmail.uwaterloo.ca...
Quote

> On Mon, 13 Aug 2001, ntlWorld News wrote:

> > Use the CreateToolHelp32Snapshot function, look it up in Win32 help, it
will
> > (along with a few other ToolHelp functions) allow you to get a complete
> > process list including executable names and paths as well as other
useful
> > info like Process IDs and parent Process IDs

> The toolhelp functions work in 95/98/ME and 2000 but not NT 4.

[...]

Other Threads