问题
Hello there i would like to know if it is possible to make a simple Hello World program in Windows (and then advance to actual ones) invisible. By that I mean, when I execute the program there will be no graphical indication whatsoever. No cmd printing "Hello world", no taskbar label, no system tray icon,nothing. I want the program to execute silently without bothering me.
So what am I thinking here people? Is that doable? Would it be like a service? I have no idea.
I would like to code it in C/C++ btw.
回答1:
How you deal with this depends on the kind of Windows application you have.
If you want a program to run when you boot and stop when you shut down, then pursue writing a Windows Service, which is doable, but is not as simple as writing a regular user-mode application. Debugging a service lies somewhere in between a regular application and a device driver, more like an application, but you have to use Microsoft template hooks so you can gain debugging control.
If you simply want a silent console and it's a Windows application (main window and all that) you can create the window so it does not display initially.
If it is a console application, you should be able to redirect the output of the console. There are Win32 library routines to manipulate a console, including closing the window, so the application can run "silently". Here is a link to those functions.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms682073%28v=vs.85%29.aspx
回答2:
If it's an application that must be launched from the user to perform some task, or, anyhow, it's some invisible application bound to the current user session, just create a GUI application without creating any window.
If, instead, such application should stay in background regardless of the logins/logouts you should write a Windows Service - but notice that it requires quite a bit of experience with windows programming to get everything right in a service; if you don't know what a Windows Service is, you probably should just stick to the first solution.
回答3:
Yes, you can make it into a service, and no console will be displayed. For more info on how to achieve this, check out this MSDN page.
来源:https://stackoverflow.com/questions/9488487/how-to-make-a-simple-hello-world-invisible-in-windows-c-c