Can an Exe retrieve its own filename

Blitz3D Forums/Blitz3D Programming/Can an Exe retrieve its own filename

RifRaf(Posted 2011) [#1]
How can you do this.. is there some windows kernel code or something? I need to know if the Blitz3D exe being ran was a specific filename, but its important that I do it from the exe itself.

Any tips as always, will be greatly appreciated.

Thanks


John Blackledge(Posted 2011) [#2]
; Returns the full exe name and path.
; Not my code, but it works.
; The original Windows call is Kernel32.




RifRaf(Posted 2011) [#3]
Thank you John, ill try this out.


stanrol(Posted 2011) [#4]
what about command$(0) or similar.


Rroff(Posted 2011) [#5]
The way John posted is AFAIK the most reliable way to do this - and the way I do it in my application (for setting icons).


RifRaf(Posted 2011) [#6]
Doesnt seem to return a valid string for me, I compiled a B3D test app with the code above.


_PJ_(Posted 2011) [#7]
Doesn't seem to work for me either, which is strange...

However, it's much quicker, as Stanrol suggsted, to use the Kernel32 function

Kernel32_GetCommandLine()



With the decls:
.lib "Kernel32.dll"
Kernel32_GetCommandLine$ () : "GetCommandLineA"



This returns the FULL path name, already enclosed in Chr(34) characters!


Rroff(Posted 2011) [#8]
EDIT: John has provided just the functions it doesn't work copy n pasting the code and pressing F5 :D

Last edited 2011


_PJ_(Posted 2011) [#9]
EDIT: John has provided just the functions it doesn't work copy n pasting the code and pressing F5 :D



Of course, but even with the DECLS in place and running from a compiled test, it doesn;t work on my machine.

Anyway, I still stand by my suggestion as being much more efficient to implement:

Once the DECLS are in, then there's no need for any separate function call, since the Userlib member function doies exactly what's required.

Last edited 2011

Last edited 2011


RifRaf(Posted 2011) [#10]
Works great Malice, thanks.


_PJ_(Posted 2011) [#11]
Just to note, you may wish to check for command line parameters which will also be present after the filepath. This part of the returned string will EXACTLY matc that of CommandLine(), so something like:

Path$=Kernel32_GetCommandLine$()
If (CommandLine()<>"") Then  Path=Left(Path,Len(Path)-Len(CommandLine))

Or similar ;)