The name of the executable running is received from the Main program as the first parameter.
To retrieve the executable name and save in a string you can simply use this:
strcpy (pgm, argv[0]);
In a similar way can be retrieved command-line parameters issued to the exe, which are stored in the argv[] array after the filename.
As an example, if you launch the exe with one command-line parameter
"myexe.exe /parm1"
you will have in argv array:
argv[0] = "myexe.exe"
argv[1] = "/parm1"