• Advertisement
Sign in to follow this  

background process?

This topic is 4350 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, i'd like to know if there is something similar as CreateProcess()? I was thinking more in external libraries(as SDL or such). If nothing else, i'd like some links to good tutorials/examples of CreateProcess(). ty

Share this post


Link to post
Share on other sites
Advertisement
okay, but now that i've created a new process, how do i execute something(for instance, defrag.exe /f)?

Share this post


Link to post
Share on other sites
Why not use ShellExecute/Ex for something as simple as that?

Share this post


Link to post
Share on other sites
Quote:
Original post by homeboye
okay, but now that i've created a new process, how do i execute something(for instance, defrag.exe /f)?

// get system settings to create new process
STARTUPINFO info;
GetStartupInfo( &info );

// process info struct to get info
PROCESS_INFORMATION pinfo;

// launch process
CreateProcess( NULL, // module name (unused)
"defrag.exe /f", // command line
NULL, // process attributes
NULL, // thread attributes
FALSE, // inherits handle?
NORMAL_PRIORITY_CLASS, // thread priority
NULL, // environment
NULL, // current directory
&info, // startup info
&pinfo // process info
);


Note that the command-line argument is automagically executed when you call the function.

Share this post


Link to post
Share on other sites
ShellExecute(HWND(), char(), "defrag", "-f c:", char(), SW_NORMAL);

Shorter, no? - Though of course, with CreateProcess you get more options, but if you're just looking for something simple, I guess ShellExecute will suit you just fine.

Share this post


Link to post
Share on other sites
Quote:
Original post by raz0r
ShellExecute(HWND(), char(), "defrag", "-f c:", char(), SW_NORMAL);

Shorter, no?

Just to satisfy my own curiosity (because MSDN isn't exactly that descriptive); but does that execute defrag in a separate process? (ie, would the above call block until the disk was defragged?) I guess the choice of function, inevitably, comes down to the desired usage.

EDIT (in response to the response to this post because I'm too lazy to make a new post): Hooray!

Share this post


Link to post
Share on other sites
Quote:

Just to satisfy my own curiosity (because MSDN isn't exactly that descriptive); but does that execute defrag in a separate process?

Of course.

Share this post


Link to post
Share on other sites
Mushu: sry, the code didn't work. i've also tried the example from the MSDN, but it was the same :raz0r: works great

ty all for help!

Share this post


Link to post
Share on other sites
Quote:
Original post by homeboye
meh, it doesn't work :a console window opens and closes in a blink of an eye and that's that.
Try running a different program. Defrag is exiting imediately, probably because some parameter is wrong.

Quote:
the code from raz0r works, but i can still see the window - it's not ran in the background.

is there any way to do that?
ShellExecute() calls CreateProcess() internally. Defrag is a console-based app, so naturally the window will stay there.

What exactly do you mean by running in the background? Have it working like how it is with ShellExecute(), but have the window hidden? The only way that's possible with console based apps that I know if is to overide the std handles to the process.

What exactly are you trying to achieve?


EDIT: Too late, never mind.

Share this post


Link to post
Share on other sites
that was fast...
anyways, nvm about the console window, just realized i don't need that to be solved.
but i have another problem now:
i have modified the code that raz0r give me to open a program that would clean my pc... anyways, i've did this:
ShellExecute(HWND(), char(), "clean", "d:\zdelamo\zzNewFolder /e /f", char(), SW_NORMAL);

it opens&closes the console real fast and the cleaning process did not appear on the taskmngr or did any other windows opened.
on the bright side(sigh) i did got this errors, i don't know how i would get rid of them though:
[Warning] unknown escape sequence '\z' 
[Warning] unknown escape sequence '\z'


ty

Share this post


Link to post
Share on other sites
thats because you are using backslashes!

"\n" (where "n" may be any character) might be interpreted by your computer as a special control-character (like tab, backspace, nextline, etc.).

as long as i know "\z" doesn't map to any of these characters so you get your error.

well since you need to use backslashes insert "\\" instead of your lonely "\".
your path with look like this then :
"d:\\zdelamo\\zzNewFolder /e /f"


PS .: you might try to read a bit more into character-arrays in C...

Share this post


Link to post
Share on other sites
If you don't want to see the console output window, in this instance, you can pass SW_HIDE to ShellExecute instead of SW_NORMAL.

[Edited by - raz0r on March 29, 2006 9:12:55 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement