Jumbo
Jumbo

Reputation: 543

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

Upvotes: 3

Views: 17947

Answers (4)

user3451413
user3451413

Reputation: 1

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

Upvotes: -1

Adam Douglass
Adam Douglass

Reputation: 45

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.

Upvotes: 3

Cody Gray
Cody Gray

Reputation: 244732

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.

Upvotes: 4

Brian Clapper
Brian Clapper

Reputation: 26211

This might help: http://ss64.com/nt/start.html

Upvotes: 1

Related Questions