問題:我有一個不應該被看到的控制檯程序。 現在(它重置IIS和刪除臨時文件。)如何隱藏控制檯窗口?
我能設法隱藏窗口後立即啓動這樣的:
static void Main(string[] args)
{
var currentProcess = System.Diagnostics.Process.GetCurrentProcess();
Console.WriteLine(currentProcess.MainWindowTitle);
IntPtr hWnd = currentProcess.MainWindowHandle;//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
}
問題是這樣的顯示窗口一秒鐘,眨眼。 有沒有控制檯程序的任何構造函數,我可以在顯示之前隱藏窗口?
其次:
我用
[System.Runtime.InteropServices.DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
,我不喜歡它的32。有沒有辦法做到這一點沒有DllImport?
.NET方式?
爲什麼你不喜歡'user32.dll'的名字? – 2010-08-25 07:37:57
'user32.dll'不是一個專門的32位DLL,並且可以在所有當前版本的Windows上使用,無論體系結構如何。這個名字是一個可以追溯到NT4的傳統。 – 2010-08-25 07:40:16