Two years ago I used CreateProcess to run applications with command line parameters. And I've discovered that when I add command line it stopes working. Say if run C:\WINDOWS\explorer.exe it starts OK but when I run C:\WINDOWS\explorer.exe param - CreateProcess fails. I spent a day trying to figure out why it failed but eventually found different solution that solved my problem and forgot about that for a while. But I still wonder what I'm doing wrong? So I wrote a simple example that demonstrates what I'm talking about.

; #########################################################################
.586
.model flat, stdcall
option casemap :none
; #########################################################################
include \masm32\include\windows.inc
include \masm32\include\windowsc.inc

include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
.DATA
CMD db "C:\WINDOWS\explorer.exe",0
; CMD db "C:\WINDOWS\explorer.exe wwww",0
processInfo PROCESS_INFORMATION <>
startInfo STARTUPINFO <>
.DATA?
hInstance HINSTANCE ?
.CODE
start:
invoke GetStartupInfo,ADDR startInfo
invoke CreateProcess,ADDR CMD,NULL,NULL,NULL,FALSE,\
NORMAL_PRIORITY_CLASS,\
NULL,NULL,ADDR startInfo,ADDR processInfo
invoke ExitProcess,eax
end start


If I uncomment
; CMD db "C:\WINDOWS\explorer.exe wwww",0
and comment
CMD db "C:\WINDOWS\explorer.exe",0
CreateProcess will fail.

But at the same time I can use 'shell' of masm32 library that is all so using CreateProcess that receives only one parameter and works fine.
What am I doing wrong? How to pass command line parameters to CreateProcess? What am I missing in understanding of CreateProcess?
PS I read API help so I know where they should be and I know that there two ways to transmit paramaters but... it doesn't work for me!
Posted on 2002-12-10 04:51:33 by Spot
Spot, I suggest you read about the api call on MSDN OR in the win32api
help file. Because when you use CreateProcess, you can either seperate the
command/commandline OR put both inside the cmdline parameter of CreateProcess.
[color=sienna]

cmd db "program_name",0
[color=red]cmdline db "program_param",0[/color]
invoke CreateProcess,addr cmd,[color=red]addr cmdline[/color],0,0,0,\
NORMAL_PRIORITY_CLASS,0,0,addr startInfo,addr processInfo

[b][size=24][color=blue]OR[/color][/size][/b]

[color=red]cmdline db "program program_param",0[/color]
invoke CreateProcess,0,[color=red]addr cmdline[/color],0,0,0,\
NORMAL_PRIORITY_CLASS,0,0,addr startInfo,addr processInfo
[/color]
Another thing, this has nothing todo with the MASM32 package. So this should
have been posted in the Main forum.
Posted on 2002-12-10 05:31:50 by natas
Thanks. I thought that lpApplicationName could contain parameters as well.
Sorry for offtopic.
Posted on 2002-12-10 06:40:16 by Spot
You want to run C:\WINDOWS\explorer.exe? Pardon my ignorance but explorer.exe is the main executable
running under the operating system.What you want to do? :stupid:

Regards,

Vortex
Posted on 2002-12-11 03:27:25 by Vortex

You want to run C:\WINDOWS\explorer.exe? Pardon my ignorance but explorer.exe is the main executable
running under the operating system.What you want to do? :stupid:
Vortex


First of all I put IE here in order to allow the majority of readers to reproduce the conditions I have had on my PC. I'm sure that 90% have windows + explorer installed in WINDOWS folder.

What do you mean under 'main' executable?

As to what one can do with Explorer the answer depends on under what operating system one is running it. Since IE supports command line any appropriate command will be acceptable.
Posted on 2002-12-11 04:11:18 by Spot
IE stands for Internet Explorer.Now you want to run explorer.exe or iexplore.exe? Which one of them?

An example:




.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

.data
cmdline db 'c:\windows\explorer.exe '
parameter db 'c:\windows',0
.code
start:
invoke WinExec,addr cmdline,SW_SHOW
invoke ExitProcess,0
end start

Posted on 2002-12-11 04:34:30 by Vortex


What do you mean under 'main' executable?


Explorer.exe is the main executable of windows.If you terminate the execution of this module,windows will stop running normally. (Disappear of desktop!)
Run the task manager:
Posted on 2002-12-11 04:42:18 by Vortex
Vortex, he doesn't want to close explorer.exe, he just wants to run explorer.exe (which opens the "Windows Explorer"). I don't really see the problem.
Posted on 2002-12-11 04:51:29 by Qweerdy
I know that he doesn't want to close it.Just IE (Internet Explorer - activated by iexplore.exe) and Windows
Explorer (explorer.exe) are different things.

Regards,

Vortex
Posted on 2002-12-11 04:55:46 by Vortex
Vortex, Row, row, row your boat... ( :grin: )
Posted on 2002-12-11 05:05:12 by natas

Vortex, Row, row, row your boat... ( :grin: )


Amigo,what do you mean? Something wrong by me?
Posted on 2002-12-11 05:12:55 by Vortex
Where did I mention that I want to terminate explorer.exe?

When your command line is 'explorer.exe c:/' you're starting a new thread of Explorer.
When your command line is 'explorer.exe http://www.google.com' Explorer starts a new task: iexplore.exe
Since the location of iexplore IS NOT in the path of the system by default you can't simply run iexplore.exe with params, the simpliest way to start iexplore automatically (explorer v5.x, v6.x) is to run explorer.exe with URL as the param. And you can't give the system 'start http://www.yahoo.com' as you might do under 9x.

Otherwise you would have to search for the default HTTP agent in the registry before you're sure what to run to open URL you need using CreateProcess function.
Posted on 2002-12-11 05:13:46 by Spot


Amigo,what do you mean? Something wrong by me?

My little fuzzy amigo, I was just pulling your leg.( :grin: ) Because I cannot
see how you could believe that he was going to spawn the shell
from his program. He only presented it as a default parameter. ( ;) )
Posted on 2002-12-11 05:19:19 by natas
No problem Spot,just a small demonstration about the critical importance of explorer.exe.Yes you can launch
the IE by explorer.exe also.

Natas,i am not so little,27 years old! :grin: Yet,thanks for your interest
Posted on 2002-12-11 05:20:03 by Vortex

No problem Spot,just a small demonstration about the critical importance of explorer.exe.Yes you can launch
the IE by explorer.exe also.


I believe I put before the public a very stupid question with CreateProcess. Still thanks for the warning.
PS The first question I ask women when they're telling me they know computers is What the button 'Scroll Lock' for?

As to the importance of the explorer....
A little boy comes into his father's room only to see him doing a coding of a huuuuge program as usual.
- Father, do you know that the Sun rises on the East and sets on the West?
Father (abstractedly), - What? Are you sure?
- Yes, father.
- Do you want to say it does it each day and never fails?
- Yes
- Did you check it allright?
- Yes, it rises and sets each day.
- Unbelievable!! Son, just don't touch anything.
Posted on 2002-12-11 06:14:26 by Spot
No,no Spot... Your question is not so wrong as you think.You encouraged me to try this example,but it doesn't
work. Can you help me? I think i made a simple mistake! Errare humanum est... :)

Regards,

Vortex




.386
.model flat,stdcall
option casemap:none

include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib

.data
cmd db 'c:\windows\explorer.exe '
parameter db 'http://www.yahoo.com',0

.data?
startinfo STARTUPINFO <?>
processinfo PROCESS_INFORMATION <?>
.code
start:
invoke CreateProcess,ADDR cmd,0,0,0,0,NORMAL_PRIORITY_CLASS,\
0,0,ADDR startinfo,ADDR processinfo
invoke ExitProcess,0
end start

Posted on 2002-12-11 06:37:16 by Vortex
Vortex, didnt you read my first post? There I explain that in order to use a
commandline, you need to either seperate the program/cmdline or put both the
program/commanline where the commandline should be. Check the post. ( ;) )

BTW: Where is that image from? What program?
Posted on 2002-12-11 06:53:48 by natas
natas: picture is taken from OllyDbg (CPU dump & Registers)
Posted on 2002-12-11 07:05:38 by TBD
I din't run the program yet but look at this
cmd db 'c:\windows\explorer.exe '

There is a string in your code that is not null terminated and there is an explicit SPACE
change it on
cmd db 'c:\windows\explorer.exe ',0

natas has pointed out a mistake in my first post. Program name can not contain parameters. That's why it didn't work. Your code just has synatx errors.
Posted on 2002-12-11 07:23:59 by Spot

natas: picture is taken from OllyDbg (CPU dump & Registers)
Thanks TBD! I havent taken the time to check it out yet. Ive been
using alot of different debuggers. Still I havent found something I really like.
So Im going to look at OllyDbg. Maybe thats what ive been looking for.( ;) )
Posted on 2002-12-11 07:25:31 by natas