QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: hanness on April 14, 2019, 01:34:15 pm

Title: Can I get the name of the executable I am running from within the program?
Post 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.

Title: How to read parameters passed to a QB64 program
Post by: hanness on April 14, 2019, 01:36:38 pm
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!
Title: Re: How to read parameters passed to a QB64 program
Post by: bplus on April 14, 2019, 01:40:57 pm
Hi hanness,

This should help: http://qb64.org/wiki check out COMMAND$
Title: Re: Can I get the name of the executable I am running from within the program?
Post by: FellippeHeitor on April 14, 2019, 01:51:59 pm
The answer to both questions is the COMMAND$() function as bplus indicated.

Code: QB64: [Select]

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):

Code: QB64: [Select]

To read just the executable name, without the path:

Code: QB64: [Select]
Title: Re: Can I get the name of the executable I am running from within the program?
Post by: hanness on April 14, 2019, 02:11:21 pm
Fantastic! Thanks again for the help.
Title: Re: Can I get the name of the executable I am running from within the program?
Post by: TempodiBasic on April 14, 2019, 02:13:02 pm
Hi hanness

Quote
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