1. Home
  2. Computing & Technology
  3. Delphi Programming

How to get the filename of the process that is currently executing

By Zarko Gajic, About.com

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;
~~~~~~~~~~~~~~~~~~~~~~~~~

Delphi tips navigator:
» Delphi Split / Tokenizer functions
« Close your application with the ESC key

Zarko Gajic
Guide since 1998

Zarko Gajic
Delphi Programming Guide

Explore Delphi Programming
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Delphi Programming
  4. Coding Delphi Applications
  5. Delphi Tips and Tricks
  6. 2002 Delphi Tips
  7. How to get the filename of the process that is currently executing

©2009 About.com, a part of The New York Times Company.

All rights reserved.