BBS: Inland Empire Archive Date: 03-29-93 (15:27) Number: 327 From: JOE NEGRON Refer#: NONE To: SEAN SULLIVAN Recvd: NO Subj: Need a routine Conf: (2) Quik_Bas
SS> I know I've seen a routine for determining the directory from which a
> program was launched, but can't remember where. Anyone have this info?
Here you go:
============================== Begin code ==============================
DEFINT A-Z
'$INCLUDE: 'qbx.bi'
DECLARE FUNCTION ProgName$ ()
'***********************************************************************
'* FUNCTION ProgName$
'*
'* PURPOSE
'* Uses DOS ISR 21H, Function 51H (Get PSP Address) to return the
'* name of the currently executing program.
'*
'* EXTERNAL ROUTINE(S)
'* QBX.LIB
'* -------
'* SUB Interrupt (IntNum%, IRegs AS RegType, ORegs AS RegType)
'***********************************************************************
FUNCTION ProgName$ STATIC
DIM IRegs AS RegType, ORegs AS RegType
IRegs.ax = &H5100 'DOS Function 51h
Interrupt &H21, IRegs, ORegs ' Get PSP Address
DEF SEG = ORegs.bx
EnvSeg% = PEEK(&H2C) + PEEK(&H2D) * 256 'Get environment address
DEF SEG = EnvSeg%
DO
Byte% = PEEK(Offset%) 'Take a byte
IF Byte% = 0 THEN 'Items are ASCIIZ terminated
Count% = Count% + 1
IF Count% AND EXEFlag% THEN 'EXE also ASCIIZ terminated
EXIT DO 'Exit at the end
ELSEIF Count% = 2 THEN 'Last entry in env. terminated
EXEFlag% = TRUE ' with two NULs. Two bytes
Offset% = Offset% + 2 ' ahead is the EXE file name.
END IF
ELSE 'If Byte% <> 0, reset
Count% = FALSE ' zero counter
IF EXEFlag% THEN 'If EXE name found,
Temp$ = Temp$ + CHR$(Byte%) ' build string
END IF
END IF
Offset% = Offset% + 1 'To grab next byte...
LOOP 'Do it again
DEF SEG 'Reset default segment
ProgName$ = Temp$ 'Assign Temp$ to the FUNCTION
Temp$ = "" 'Clean up
END FUNCTION
=============================== End code ===============================
--Joe in Bay Ridge, Brooklyn, NY, Mon, 03-29-1993--
... Old enough to know better; too young to resist.
___
X Blue Wave/QWK v2.12 X
--- Maximus 2.01wb
* Origin: * BlueDog BBS * (212) 594-4425 * NYC FileBone Hub (1:278/709)

Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET