TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: ALL
from: BRIAN MCLAUGHLIN
date: 1998-03-14 10:14:00
subject: Code to retrieve program

From: Brian McLaughlin 
Subject: Code to retrieve program name
 
The code below will retrieve the full path and name of your
program, while it is running. This is not only useful to
establish where your user installed your program, but also
guards against the user renaming your program. I have used it
to locate the CFG (configuration) file for my programs, by
making it a rule that CFG files must be in the same directory
as the EXE file. The CFG file then tells me where the data files
are located. I am releasing the code to the public domain.
 
$LIB ALL OFF
 
DECLARE FUNCTION ProgName$ ()
 
'Demo code ---------------------------------------------------------
 
 PRINT "The currently running program is "; ProgName$
 PRINT
 PRINT "  NOTE: When run in PB.EXE, this will print [path\] PB.EXE. "
'-------------------------------------------------------------------
 
'===================
 FUNCTION ProgName$
'===================
'  This function returns the name, under which the currently running
'  program was started up. Requires DOS 3.3 or better.
 
DIM NSeg AS LOCAL WORD
DIM NOff AS LOCAL WORD
DIM Prog AS LOCAL STRING
 
    Prog = SPACE$(65)
 
NSeg = STRSEG(Prog)
NOff = STRPTR(Prog)
 
ASM   Push DS
ASM   Push SI
ASM   Mov  AX, &H6200
ASM   Int  &H21
ASM   Mov  DS, BX         ; point DS at PSP segment
ASM   Mov  BX, &H2C
ASM   Mov  AX, [BX]
ASM   Mov  DS, AX
ASM   Xor  SI, SI         ; points DS:SI at first byte of environment
 
ContinueSearch:
 
ASM   Lodsb               ; get one byte from environment
ASM   Or   AL, AL         ; look for a single null char
ASM   Jnz  ContinueSearch      ; if not null, continue
ASM   Lodsb                    ; look at next char
ASM   Or   AL, AL              ; is it null, too?
ASM   Jnz  ContinueSearch      ; if not null, continue
ASM   Add  SI, 4          ; DS:SI points at program name
ASM   Mov  AX, NSeg
ASM   Mov  ES, AX
ASM   Mov  BX, NOff       ; ES:BX points to Prog
 
LoadName:
 
ASM   Lodsb
ASM   Or   AL, AL
ASM   Jz   NameLoaded
ASM   Mov  Byte Ptr ES:[BX], AL
ASM   Inc  BX
ASM   Jmp  LoadName
 
NameLoaded:
 
ASM   Pop  SI
ASM   Pop  DS
 
  ProgName$ = RTRIM$(Prog$)
 
END FUNCTION
 
*** QwkNews (tm) v2.1
 * [TN71] Toast House Import
--- GEcho 1.20/Pro
---------------
* Origin: Toast House Remote (1:100/561)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.