[英].Net Console Application that Doesn't Bring up a Console
我有一個控制台應用程序,我用來通過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服務?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.