Page 1 of 1

Determine the name of the running executable.

Posted: Wed Sep 06, 2006 11:32 am
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.

Posted: Wed Sep 06, 2006 11:46 am
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?

Checking the currently running EXE file name

Posted: Wed Sep 06, 2006 1:52 pm
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

Posted: Wed Sep 06, 2006 4:26 pm
by ManaUser
This looks like a different method than what I used before, but it does what I need. Many thanks!