.data

programname db "%COMSPEC%",0
progcmdline db "/C START C:\WINNT\NOTEPAD.EXE"

processInfo PROCESS_INFORMATION <>
startInfo STARTUPINFO <>

.code

start:

invoke CreateProcess,programname,progcmdline,NULL,NULL,FALSE,\
NORMAL_PRIORITY_CLASS,\
NULL,NULL,ADDR startInfo,ADDR processInfo

invoke ExitProcess,NULL

end start
....
after compiling and trying to run the EXE it crashes :(, it works perfect if i don't use %comspec% to start notepad, but %comspec% is the way i want to go.

How do i fix this (code would be preferred!)? im using MASM v6, & W2k.

Thanks in advance, help is always heavily appreciated!
Posted on 2001-11-24 07:40:55 by ashtr3jd
Two things:
1) I think you need "ADDR programname" and "ADDR progcmdline" as passing a string is usually done by reference (this could be one cause of your crash).

2) The string "%COMSPEC%" is probably not evaluated, it is used directly (ie. As a literal string).
Try the following:


.data
env db "COMSPEC",0
progcmdline db "/C START C:\WINNT\NOTEPAD.EXE", 0
buffer db 2048 dup (0)

processInfo PROCESS_INFORMATION <>
startInfo STARTUPINFO <>

.code
start:
invoke GetEnvironmentVariable, ADDR env, ADDR buffer, SIZEOF(buffer)
invoke CreateProcess, ADDR buffer, ADDR progcmdline, NULL, NULL, \
FALSE, NORMAL_PRIORITY_CLASS, NULL,NULL, \
ADDR startInfo,ADDR processInfo

invoke ExitProcess, eax
end start


The code may not work exactly, I'm working off the top of my head, but its about right...

Mirno
Posted on 2001-11-24 11:37:40 by Mirno
you 0wn Mirno :alright:

worked perfectly just changed
invoke GetEnvironmentVariable, ADDR env, ADDR buffer, SIZEOF (buffer)

to --> invoke GetEnvironmentVariable, ADDR env, ADDR buffer, SIZEOF buffer

i guess even the best can miss things (like ADDR ;) )

Thanks again :)
Posted on 2001-11-24 12:59:38 by ashtr3jd