问题:我有一个不应该被看到的控制台程序。 现在(它重置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