Hi there all,

I was woundering how you can get the name of the executable file. i.e. if the executable file is called "file.exe", how can I get the file to know this as it is running. For example, to print out its own name no matter what it is.

Sorry if this isn't making much sence.


Steven

P.S I am using HLA if that makes any difference.
Posted on 2004-03-29 07:44:55 by nerobot
I think you can use GetModuleFileName()
Posted on 2004-03-29 07:47:04 by bj1500
push 00
call GetModuleHandleA

push module_filename_buffer_size ; fill this in yourself
push offset module_filename_buffer
push eax
call GetModuleFilenameA

............

call GetCommandLineA

also returns the module filename, but you have to parse it
Posted on 2004-03-29 08:57:30 by evlncrn8
You can just use NULL for the module handle, this will parse the path and filename if you want them separate, it is not very efficient but it does not have to be as it is only called once and is wrapped between two API calls :

.data

ExePath DB MAX_PATH DUP (?)
ExeName DB MAX_PATH DUP (?)

.code
invoke GetModuleFileName,NULL,offset ExePath,MAX_PATH
std
mov ecx,eax
mov edi,offset ExePath
add edi,eax
mov eax,5Ch
repne scasb
mov B[edi+1],0 ; << Replace B with BYTE PTR for MASM
cld
add edi,2
invoke lstrcpy, offset ExeName,edi
Posted on 2004-03-29 09:06:07 by donkey