2

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

Jumbo
  • 523
  • 3
  • 8
  • 14
  • 1
    in order to answer this question its important to know what framework you are using: MFC, .NET, or just the native Win32 API? – Chris Becke Dec 27 '10 at 07:02

4 Answers4

3

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.

Community
  • 1
  • 1
Cody Gray
  • 230,875
  • 49
  • 477
  • 553
1

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.

Community
  • 1
  • 1
1

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

Brian Clapper
  • 24,425
  • 7
  • 63
  • 65
  • 2
    this answer would apply if this was superuser.com – Chris Becke Dec 27 '10 at 07:08
  • 1
    This is not "programmatically". – Cody Gray Dec 27 '10 at 11:19
  • He can certainly "programmatically" create a Windows service, or otherwise arrange to put the process in the background. On the other hand, he could also "programmatically" simply arrange to use the START command. You can defined "programmatically" how you see fit, but sometimes, the simplest solution (use the existing command infrastructure) fits, regardless of how you choose to parse "programmatically." – Brian Clapper Dec 27 '10 at 14:20
0

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