I've searched the board several times, but haven't found anything about getting the name of the program itself.
Printable View
I've searched the board several times, but haven't found anything about getting the name of the program itself.
Can you be more specific.. getting the name of the program your running? Name of what...?
ok. My program is obvious.exe and when you run it, I want to MessageBox obvious.exe. If, however, you rename it to ah.exe, the program should MessageBox ah.exe
have you tried to look in argv[0]?
Code:int main(int argc, char* argv[]) {
printf("%s", argv[0]);
return 0;
}
ggCode:#include <stdio.h>
int main (int argc, char *argv[])
{
printf("%s", argv[0]);
return 0;
}
well i figured you'd guys be smart enough to figure out that I put this in the Windows section for a reason...
Is there no api function to retrieve this?
I usually view new threads, and don't look in which forum they are.Quote:
Originally posted by neandrake
well i figured you'd guys be smart enough to figure out that I put this in the Windows section for a reason...
Is there no api function to retrieve this?
Hmm, have you looked in lpCmdLine? Maybe Windows has something similar to argv[0].
Yes, I have tested lpCmdLine and it doesn't include the name, only arguments/parameters passed to the program.
Could you please explain more? what do you mean by "I want to MessageBox obvious.exe?" Do you want to show a message box containing the exe name?Quote:
Originally posted by neandrake
ok. My program is obvious.exe and when you run it, I want to MessageBox obvious.exe. If, however, you rename it to ah.exe, the program should MessageBox ah.exe
I was just giving an example. I know how to MessageBox. I'm trying to make a sort of 'install' for my program and I need to know the location (gotten with GetCurrentDirectory()) and I need to get the name of the program (in case someone renames it). If my program was "C:\Program Files\MyProgram\Barfsnort.exe" but the user decided to rename it to Snortbarf.exe, then I have to update settings.
All I need to know is how to get the name of the program
call the function GetCommandLine().
Code:#include <windows.h>
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
{
MessageBox(NULL, GetCommandLine(), "Program exe: ", MB_OK);
return 0;
}
slick hybrid, very slick
god I knew it was a one-liner
That call will include command line arguments though, if they exist.
damnit
lool
hrm
So I use a string function to remove lpCmdLine from GetCommandLine(), and it should be fine, right?
Well in a call to GetCommandLine() the exe path is in quotes of its own, so it shouldn't be too hard to separate.