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

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

By , About.com Guide

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

Explore Delphi Programming
About.com Special Features

The Best Web Trends of the Decade

A look back at the best innovations, ideas and technologies over the last 10 years, More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. 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

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

All rights reserved.