Tal
Tal

Reputation:

How to make console program to disappear and work in background?

How can I make console program disappear and work in the background? I mean, I don't want to see the program, but I want to see it running in the task manager.

Thanks.

Upvotes: 4

Views: 5378

Answers (6)

Software_Designer
Software_Designer

Reputation: 8587

On Windows use ShowWindow(FindWindowA("ConsoleWindowClass", NULL), false) to hide the console window. It will still be running in the background and is not visible on the taskbar.

However you will have to run a task manager like Taskmgr.exe to find it and shut it down.

#include <windows.h>  
#include <iostream>     
using namespace std;


int main () {   
    ShowWindow(FindWindowA("ConsoleWindowClass", NULL), false);
    while(true) {
                 // Do your hidden stuff here
    }   
return 0;
}

Upvotes: 0

Anthony Potts
Anthony Potts

Reputation: 9160

You could alternatively make one that goes to the system tray. This would also allow you to add a Kill Process directly from the system tray instead of going to the task manager. In .NET I have used the following: http://www.developer.com/net/csharp/article.php/3336751

This may offer a few advantages.

Upvotes: 2

Brian Ensink
Brian Ensink

Reputation: 11218

Assuming you cannot modify the console application and make it a windowless application you could create a windowless application that launches the console program and redirects all the standard input and output streams to "dummy" streams.

Upvotes: 0

ng.
ng.

Reputation: 7189

If you are using Windows try

start command.exe

If you are using *nix

nohup command

Upvotes: 0

Arjan Einbu
Arjan Einbu

Reputation: 13692

Assuming Windows and .NET:

You could set its output type to "Windows Application", and it will not open the console window....

Or you could create a Windows Service...

Upvotes: 3

JB King
JB King

Reputation: 11910

Assuming a MS Windows XP environment:

My suggestion would be to consider making a Windows Service to do what you are asking, though another possibility would be to set something up within msconfig to run the program at startup or in the startup group within the "Start->All Programs->StartUp" section.

If you are on a Mac, Linux or some other O/S, there may exist a similar function to act as a place to run programs within the background.

Upvotes: 0

Related Questions