Author Topic: Can I get the name of the executable I am running from within the program?  (Read 2885 times)

0 Members and 1 Guest are viewing this topic.

This topic contains a post which is marked as Best Answer. Press here if you would like to see it.

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
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.


Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
How to read parameters passed to a QB64 program
« Reply #1 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!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How to read parameters passed to a QB64 program
« Reply #2 on: April 14, 2019, 01:40:57 pm »
Hi hanness,

This should help: http://qb64.org/wiki check out COMMAND$
« Last Edit: April 14, 2019, 01:42:07 pm by bplus »

Marked as best answer by hanness on April 14, 2019, 10:11:36 am

FellippeHeitor

  • Guest
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]
« Last Edit: April 14, 2019, 01:54:40 pm by FellippeHeitor »

Offline hanness

  • Forum Regular
  • Posts: 210
    • View Profile
Fantastic! Thanks again for the help.

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
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

but it seems that your question is gone over and you have got two excellent answers.

Welcome and Good luck  with QB64
Programming isn't difficult, only it's  consuming time and coffee