how can i extract the running application i.e .exe or .com file name
my guess goto PSP for .com and MZ exe header info for .exe file,a'm i some near

plz guide me
Posted on 2006-07-16 13:25:57 by sihotaamarpal
I would think the com/exe filename is located in the command-line located in the PSP... after you fetch that, you can use the "truename" or whatever it's called ("canonical filename", perhaps?) DOS call to get the fully-qualified path.
Posted on 2006-07-16 13:48:14 by f0dder
hi f0dder
can u plz write a small code snippet how to fetch
Posted on 2006-07-17 00:42:03 by sihotaamarpal
Sorry, I haven't done 16bit programming for ages, so I'd have to search for some references before being able to come up with a snippet... but This Post might be a good starting point.
Posted on 2006-07-17 06:10:20 by f0dder
ok f0dder i wait for u or some one u provide me some help regarding this
Posted on 2006-07-17 07:48:05 by sihotaamarpal

ok f0dder i wait for u or some one u provide me some help regarding this

Take a look at the link in my previous post, it shows how to get at the commandline from the PSP area.
Posted on 2006-07-17 07:55:59 by f0dder
hi f0dder i try this way but it
prints the command line arguments not the file name

i want something like

void main(int argsc,char args[])

when u run program just by clicking it prints the "filename with whole path"

MODEL small





          PUSH ES    ; save es and
          PUSH DS    ; ds
          MOV AH,51H ;regeuest of PSP address into BX register
          INT 21H
          MOV ES,BX  ;copied PSP into es
          MOV DS,BX  ;and ds
          MOV AL,0DH  ;serach for <enter> char
          MOV CX,21  ;no of bytes
          MOV DI,82H  ;start address of PSP
          REPNZ SCASB ;sacn for <enter>
          JNZ EXIT_  ;not found error
          DEC DI      ;found
          MOV ES:BYTE PTR,'$' ;repalce with $ char
          MOV AH,09H  ;request to print a command line
          MOV DX,82H  ;string addressed by ds:dx
          INT 21H
          POP DS
          POP ES
          MOV AX,4C00H
          INT 21H 
Posted on 2006-07-18 13:22:21 by sihotaamarpal
When you get the command line, it shows the whole location of the file, you could simply walk through the string, find the last instance of \, and use that data, since it is the filename. And if you want to get rid of the .exe section, just ignore everything after the .
Posted on 2006-07-18 23:12:09 by Bobbias
hi Bobbias

try at prompt that code

see the result
Posted on 2006-07-19 03:39:09 by sihotaamarpal
The name string of the file being executed is located in the environment block after the double 0 bytes that end the standard environment block. I believe the segment value of the environment block is stored somewhere in the PSP.
Posted on 2006-07-20 20:32:50 by tenkey
Hi sihotaamarpal,

The offset 02Ch from the beginning of the PSP (Program Segment Prefix) contains a WORD value (16-bits long) of the segment address of the environment variable blocks. Once you retrieve the environment variableís segment block address from the specified offset you will be able to see all the environment variables including the full path of your executable file that can be found almost at the end of the variable block.

The blocks are separated by null values and your programís full path is separated from the others by 00h 01h 00h. I just coded an example, which I think might help you more than any more description.

Posted on 2006-07-21 03:00:12 by XCHG
thks XCHG for a great help and great commenting that is easily understandable
Posted on 2006-07-21 05:42:33 by sihotaamarpal