简体   繁体   中英

Create a background process in windows

How do I make a process go the background programatically?

What I want is for the user to double-click the process executable, and it just goes into the background ... and does not open a window while executing.

Any code snippet in visual c++ would be very helpful

Have you considered creating a Windows Service instead? They're specifically designed to run in the background without showing a UI.

Otherwise, just create an application without a window .

I know this is old, but I thought I would post something for when people find this through search.

While I like Cody Gray's answer for design correctness, sometimes you don't have a choice.

If you want to launch a program without jumping to the new window (it appears in the background or minimized) or not create a window at all try looking at the ShellExecute and ShellExecuteEx functions. The argument nShowCmd (or nShow ) gives you (among others) the options:

SW_HIDE

Hides the window and activates another window.

SW_SHOWMINNOACTIVE

Displays the window as a minimized window. The active window remains active.

As the documentation says, SW_HIDE creates a process running the executable you give it, but if this program would normally create a window, none appears.

这可能会有所帮助: http : //ss64.com/nt/start.html

I tried this way and it worked fine: Create a console application and write your codes in the sub main as any other console application. Now change the application type in the project properties to windows Forms application from Console application thats it

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM