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
my guess goto PSP for .com and MZ exe header info for .exe file,a'm i some near
plz guide me
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.
hi f0dder
can u plz write a small code snippet how to fetch
can u plz write a small code snippet how to fetch
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.
ok f0dder i wait for u or some one u provide me some help regarding this
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.
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[])
{
printf("%s",args[0]);
getch();
}
when u run program just by clicking it prints the "filename with whole path"
MODEL small
STACK 256
DATASEG
CODESEG
START:
MAIN PROC FAR
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
EXIT_:
MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN
prints the command line arguments not the file name
i want something like
void main(int argsc,char args[])
{
printf("%s",args[0]);
getch();
}
when u run program just by clicking it prints the "filename with whole path"
MODEL small
STACK 256
DATASEG
CODESEG
START:
MAIN PROC FAR
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
EXIT_:
MOV AX,4C00H
INT 21H
MAIN ENDP
END MAIN
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 .
hi Bobbias
try at prompt that code
command>prog.exe
see the result
try at prompt that code
command>prog.exe
see the result
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.
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.
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