Determine the name of the running executable.

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
ManaUser
Newbie
Posts: 2
Joined: Wed Sep 06, 2006 10:54 am

Determine the name of the running executable.

Post by ManaUser »

Hi all. A long time ago I found a sample QuickBasic program that could basically check it's own name. I meant to save it but now I can't find it.

Now I'm trying to make a program with quite a bit of imbedded binary data. The best way I can think of is to tack it on the end of the exe and have it OPEN itself to get it, but I want it to work even if it's been renamed, so...

Does anyone happen to know how to do this? Or if not can anyone thing of another clever solution? :)

Basically what I'm trying to create, if anyone is interested, is a self-displaying image file.
User avatar
Zim
Veteran
Posts: 98
Joined: Mon Dec 05, 2005 4:31 pm
Location: Wisconsin, USA
Contact:

Post by Zim »

I know that in a batch file, %0 returns the name of the batch file. You can test this by creating a batch file containing only

echo %0

Then running it.

Does that help?
--- Zim ---
--- Time flies like an arrow, but fruit flies like a banana ---
User avatar
Stoves
Veteran
Posts: 101
Joined: Fri Feb 10, 2006 12:24 am
Location: Nashville, TN

Checking the currently running EXE file name

Post by Stoves »

Code for checking the EXE file name

Code: Select all

DECLARE FUNCTION exename$ ()
 
DEFINT A-Z
CONST true = -1, false = 0
 
' $INCLUDE: 'qb.bi'

PRINT exename$

REM $DYNAMIC
FUNCTION exename$
 
 '
 ' This function returns the name of the exefile which is running
 '
 
DIM regs AS RegTypeX
tmp$ = ""
regs.ax = &H6200
CALL InterruptX(&H21, regs, regs)
 
DEF SEG = regs.bx
DEF SEG = PEEK(&H2C) + PEEK(&H2D) * 256
 
byte = 0
DO
 IF PEEK(byte) = 0 THEN
	IF PEEK(byte + 1) = 0 THEN
	 byte = byte + 2
	 EXIT DO
	END IF
 END IF
	 byte = byte + 1
LOOP
IF PEEK(byte) = 1 THEN
 byte = byte + 2
 DO WHILE PEEK(byte)
 tmp$ = tmp$ + CHR$(PEEK(byte))
 byte = byte + 1
 LOOP
 exename$ = tmp$
END IF
 
END FUNCTION
Running this code from within QB returns the path name where QB is running from plus "QB.EXE". Running this code from a stand-alone exe returns the path where the exe file is running from plus the file's name.

Original Code by by Tomppa: http://www.fys.ruu.nl/~bergmann/file.bas
QB.LIB File: http://student.fsb.hr/download/sharewar ... /qb/qb.lib
QB.BI File: http://student.fsb.hr/download/sharewar ... g/qb/qb.bi


Further Reading

How to Use CALL INTERRUPT with QB: http://support.microsoft.com/default.as ... n-us;43534
ManaUser
Newbie
Posts: 2
Joined: Wed Sep 06, 2006 10:54 am

Post by ManaUser »

This looks like a different method than what I used before, but it does what I need. Many thanks!
Post Reply