LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I read the file name of a .exe file when it is running

 
0 Kudos
Message 1 of 4
(3,131 Views)
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"


Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 4
(3,128 Views)
Windows SDK has a GetModuleFileName function which you can call from any function in your program.

#include
....
char myModuleName[MAX_PATHNAME_LEN];
....
GetModuleFileName(NULL,myModuleName,MAX_PATHNAME_LEN);

From the Windows SDK Help for GetModuleFileName:
The first parameter to GetModuleFileName is the handle to the module whose file name is being requested. If this parameter is NULL, GetModuleFileName returns the path for the file containing the current process.
Message 3 of 4
(3,118 Views)
The #include statement should be
#include < windows.h >
without the spaces around windows.h. The forum's HTML error detection interprets the include syntax as an HTML error and deletes it.
0 Kudos
Message 4 of 4
(3,115 Views)