'===========================================================================
' Subject: EXE Self Extractor                 Date: 10-19-03 (  :  )       
'  Author: Michael Webster                    Code: QB,PDS                 
'  Origin: mfwebster@pdq.net                Packet: ALGOR.ABC
'===========================================================================
'Self-extracting file
'Michael Webster

'This demonstrates one method. IIRC, this will not work with early versions of MS-DOS.

DEFINT A-Z 

TYPE RegTypeX 
ax AS INTEGER 
bx AS INTEGER 
cx AS INTEGER 
dx AS INTEGER 
bp AS INTEGER 
si AS INTEGER 
di AS INTEGER 
flags AS INTEGER 
ds AS INTEGER 
es AS INTEGER 
END TYPE 
DECLARE SUB InterruptX (intnum%, inRegs AS RegTypeX, outRegs AS RegTypeX) 
DIM regX AS RegTypeX 

' Call the DOS Get PSP Address function to 
' get the segment address of the PSP for 
' the current program. 
regX.ax = &H5100 
InterruptX &H21, regX, regX 

' Set the current segment to the Memory 
' Control Block that precedes the PSP. 
DEF SEG = regX.bx - 1 

' Read the owner filename from bytes 8-15. 
FOR offset = 8 TO 15 
filename$ = filename$ + CHR$(PEEK(offset)) 
NEXT 

PRINT filename$

'Another method that could be used to retrieve the full path, program name, and 
'extension would be to read it from the program's environment block. The segment 
'address of the program's environment block is at offset 2Ch in the PSP. For 
'recent versions of MS-DOS, a program's environment is terminated with 2 null 
'bytes followed by a word that indicates the number of strings that follow 
'(normally 1) followed by a null terminated string that specifies the 
'program's path and name. 

