Click to See Complete Forum and Search --> : How to implement Start menu Run command?
dc_2000
September 27th, 2006, 06:57 PM
Hi everyone:
Can someone suggest how to implement the functionality of the run command from the Windows Start menu. For example, if I type:
rundll32.exe PowrProf.dll, SetSuspendState
how to run similar command with Win32 API?
wildfrog
September 27th, 2006, 07:03 PM
If you just want to execute the application (without any input dialog etc.) you can use CreateProcess (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/createprocess.asp).
- petter
wildfrog
September 27th, 2006, 07:06 PM
Or if you want to hibernate the system you can use the SetSuspendState (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/power/base/setsuspendstate.asp) function.
- petter
dc_2000
September 27th, 2006, 07:14 PM
No, it has nothing to do with hibernation -- it's just an example I gave here. What I'm asking is how the Run window functionality from Start menu is implemenred?
wildfrog
September 27th, 2006, 07:23 PM
Well, it's a dialog box with a textbox and a button. Then when the button is pressed it grabs the entered text and then it use the CreateProcess (or similar) function is mentioned in post #2.
- petter
dc_2000
September 27th, 2006, 07:35 PM
Ok, thanks. But how do I separate ApplicationName and CommandLine for CreateProcess API? I can't use spaces as separator as a path can have spaces inside.
wildfrog
September 27th, 2006, 07:53 PM
As with the Run-dialog, you must use quotes (") around the path or arguments if they contain whitespace.
The lpApplicationName parameter can be NULL. In that case, the module name must be the first white space-delimited token in the lpCommandLine string. If you are using a long file name that contains a space, use quoted strings to indicate where the file name ends and the arguments begin; otherwise, the file name is ambiguous. For example, consider the string "c:\program files\sub dir\program name". This string can be interpreted in a number of ways. The system tries to interpret the possibilities in the following order:
c:\program.exe files\sub dir\program name
c:\program files\sub.exe dir\program name
c:\program files\sub dir\program.exe name
c:\program files\sub dir\program name.exe
- petter
dc_2000
September 27th, 2006, 07:54 PM
Also when I try to specify a file to, say, something other than a program, like:
c:\My Music\Beethoven's Symphony No. 9.mp3CreateProcess returns false. What's up with that?
PS. Tried with both quotes and without. Both returned FALSE. I set lpApplicationName = NULL and lpCommandLine="\"c:\My Music\Beethoven's Symphony No. 9.mp3\""
wildfrog
September 27th, 2006, 08:09 PM
Ahh, sorry. CreateProcess can only open application (not documents). You can use the ShellExecute (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/functions/shellexecute.asp) (with the open verb) if you need to open documents in their default application.
- petter
golanshahar
September 28th, 2006, 02:39 AM
This FAQ can also help you: How can I start a process? (http://www.codeguru.com/forum/showthread.php?t=302501)
Cheers
dc_2000
September 28th, 2006, 02:51 AM
Thank you guys!
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.