bdn.borland.com

Article #28927: How to Get the Filename of the Process that is Currently Executing.

Question: I'd like to get the filename of the process that is currently executing?

Solution: A call to GetModuleName will return the name of the file that is currently executing your code. You will need to pass it the correct handle to the module in order for it to correctly return the filename that it is associated with, specifically hInstance. Below is some sample code to return the filename:

function GetModName: String;
var
fName: String;
nsize: cardinal;
begin
nsize := 128;
SetLength(fName,nsize);
SetLength(fName,GetModuleFileName(hinstance,pchar(fName),nsize));
Result := fName;
end;

Last Modified: 30-JUL-02