QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: hanness on April 14, 2019, 01:34:15 pm
-
This may sound like a crazy question, but I'll explain in a minute why I want to do this.
Say my QB64 program is called MyProgram.exe but a user renames the executable to something else. Let's assume they call it NewProgram.exe.
I need the program to be able to determine the name with which it was launced.
More information: Thanks to this forum, I have code that let's the program determine if it was run elevated or not. I now also know how to re-launch the program in an elevated state if it was not run elevated initially. Effectively, if is now a self-elevating program. In order to do this, I need to know the name of the executable to launch. I could simply hard code the name of the execuable, but I would prefer to be able to determine the name in case someone renames it.
-
Say I create a QB64 program called MyProgram.exe. If I run that program and pass parameters to it, how can read those parameters?
Example:
MyProgram.exe 1 2 3
I want to be able to take those 3 parameters and save them to variables.
I've looked through the Help but I must be glossing over where this is discussed as I simply cannot seem to find it.
Thanks!
-
Hi hanness,
This should help: http://qb64.org/wiki check out COMMAND$
-
The answer to both questions is the COMMAND$() function as bplus indicated.
The above will give you all the parameters passed to your program.
To figure out the name of your program's executable, read COMMAND$(0):
To read just the executable name, without the path:
-
Fantastic! Thanks again for the help.
-
Hi hanness
I need the program to be able to determine the name with which it was launced.
at this wikipage you find a program that find itself using Windows API to respond to a combo keypressing...
http://www.qb64.org/wiki/Windows_Libraries#Hot_Keys_.28maximize.29 (http://www.qb64.org/wiki/Windows_Libraries#Hot_Keys_.28maximize.29)
but it seems that your question is gone over and you have got two excellent answers.
Welcome and Good luck with QB64