.Net控制台应用程序无法启动控制台

我有一个控制台应用程序,我用来通过Windows调度程序运行预定的作业。 与应用程序之间的所有通信都在电子邮件,事件记录,数据库日志中。 有什么方法可以抑制控制台窗口的出现吗?

当然。 将其构建为winforms应用程序,永远不会显示您的表单。

请注意,因为它不再是一个真正的控制台应用程序,并且在某些环境中您将无法使用它。

借鉴MSDN( 链接文字 ):

using System.Runtime.InteropServices; ... [DllImport("user32.dll")] public static extern IntPtr FindWindow(string lpClassName,string lpWindowName); [DllImport("user32.dll")] static extern bool ShowWindow(IntPtr hWnd, int nCmdShow); ... //Sometimes System.Windows.Forms.Application.ExecutablePath works for the caption depending on the system you are running under. IntPtr hWnd = FindWindow(null, "Your console windows caption"); //put your console window caption here if(hWnd != IntPtr.Zero) { //Hide the window ShowWindow(hWnd, 0); // 0 = SW_HIDE } if(hWnd != IntPtr.Zero) { //Show window again ShowWindow(hWnd, 1); //1 = SW_SHOWNORMA } 

这是一个黑客,但以下博客文章描述了如何隐藏控制台窗口:

http://expsharing.blogspot.com/2008/03/hideshow-console-window-in-net-black.html

安排任务作为与您的帐户不同的用户运行,您将不会弹出一个窗口。 。 。

只需将“计划任务”配置为“运行用户是否登录”。

为什么不将应用程序作为Windows服务?