简体   繁体   English

如何在Windows中使一个简单的Hello World“隐形”(C / C ++)

[英]How to make a simple Hello World “invisible” in Windows (C/C++)

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. 你好,我想知道是否有可能在Windows中制作一个简单的Hello World程序(然后进入实际的程序)看不见。 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. 没有cmd打印“Hello world”,没有任务栏标签,没有系统托盘图标,没有。 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. 我想用C / C ++ btw编写代码。

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. 如果它是一个必须从用户启动以执行某项任务的应用程序,或者无论如何,它是绑定到当前用户会话的一些不可见的应用程序,只需创建一个GUI应用程序而不创建任何窗口。

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; 相反,如果这样的应用程序应该保留在后台而不管登录/注销,你应该编写一个Windows服务 - 但请注意,它需要相当多的Windows编程经验才能使服务中的一切正常; if you don't know what a Windows Service is, you probably should just stick to the first solution. 如果您不知道Windows服务是什么,您可能应该坚持第一个解决方案。

How you deal with this depends on the kind of Windows application you have. 您如何处理这取决于您拥有的Windows应用程序的类型。

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. 如果您希望程序在启动时运行并在关闭时停止,那么请继续编写Windows服务,这是可行的,但并不像编写常规用户模式应用程序那么简单。 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. 调试服务位于常规应用程序和设备驱动程序之间,更像是应用程序,但您必须使用Microsoft模板挂钩,以便获得调试控制。

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. 如果您只是想要一个静音控制台,它是一个Windows应用程序(主窗口和所有这些),您可以创建窗口,使其最初不显示。

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". 有Win32库例程来操作控制台,包括关闭窗口,因此应用程序可以“静默”运行。 Here is a link to those functions. 这是这些功能的链接。

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682073%28v=vs.85%29.aspx http://msdn.microsoft.com/en-us/library/windows/desktop/ms682073%28v=vs.85%29.aspx

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 . 有关如何实现此目的的更多信息,请查看此MSDN页面

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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