【发布时间】:2010-10-30 09:53:23
【问题描述】:
我有一个控制台应用程序,用于通过 Windows 调度程序运行计划作业。与应用程序之间的所有通信都在电子邮件、事件记录、数据库日志中。有什么办法可以抑制控制台窗口出现吗?
【问题讨论】:
标签: c# .net vb.net console console-application
我有一个控制台应用程序,用于通过 Windows 调度程序运行计划作业。与应用程序之间的所有通信都在电子邮件、事件记录、数据库日志中。有什么办法可以抑制控制台窗口出现吗?
【问题讨论】:
标签: c# .net vb.net console console-application
当然。将其构建为 winforms 应用程序,从不显示您的表单。
请小心,因为它不再是真正的控制台应用程序,并且在某些环境中您将无法使用它。
【讨论】:
为什么不让应用程序成为 Windows 服务?
【讨论】:
这是一个 hack,但以下博客文章描述了如何隐藏控制台窗口:
http://expsharing.blogspot.com/2008/03/hideshow-console-window-in-net-black.html
【讨论】:
借自 MSDN (link text):
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
}
【讨论】:
安排任务以与您的帐户不同的用户身份运行,这样您就不会弹出窗口。 . .
【讨论】:
只需将计划任务配置为“无论用户是否登录都运行”。
【讨论】: