簡體   English   中英

隱藏進程窗口,為什么不起作用?

[英]Hiding the process window, why isn't it working?

我現在已經嘗試了幾種方法來隱藏新進程的窗口(在這種情況下,它只是用於測試的 notepad.exe),但無論我嘗試什么,它都無法正常工作。

我已經閱讀了很多帖子,現在都說相同,為什么它對我不起作用?

我有一個控制台應用程序,它應該在不顯示窗口的情況下啟動其他進程。

我試圖讓我的控制台應用程序在沒有窗口的情況下啟動 notepad.exe,但它不起作用。

ProcessStartInfo info = new ProcessStartInfo("path to notepad.exe");

info.RedirectStandardOutput = true;
info.RedirectStandardError = true;                                
info.CreateNoWindow = true;
info.UseShellExecute = false;                                

Process proc = Process.Start(info);

我還嘗試使用 info.WindowStyle 的各種設置,並且嘗試將我的控制台應用程序配置為 Windows 應用程序,但我做什么並不重要,子進程總是打開一個窗口。

這是控制台應用程序不允許的還是這里有什么問題 - 任何人都可以對此有所了解嗎?

我在 Windows 7 x64 上使用 .NET 4.0

根據我的經驗,每當我啟動“cmd.exe”時,以下工作。

info.CreateNoWindow = true;
info.UseShellExecute = false;                                

它似乎不適用於“notepad.exe”。 它也與其他應用程序失敗,例如“excel.exe”和“winword.exe”。

但這有效:

ProcessStartInfo info = new ProcessStartInfo("notepad.exe");

info.WindowStyle = ProcessWindowStyle.Hidden;

Process proc = Process.Start(info);

來自MSDN

窗口可以是可見的或隱藏的。 系統通過不繪制來顯示隱藏的窗口。 如果窗口被隱藏,則會被有效禁用。 隱藏窗口可以處理來自系統或其他窗口的消息,但它無法處理來自用戶或顯示輸出的輸入。 通常,應用程序可以在自定義窗口外觀時隱藏新窗口,然后使窗口樣式為“ 正常” 要使用ProcessWindowStyle.Hidden, ProcessStartInfo.UseShellExecute屬性必須為false

當我測試它時,我沒有設置UseShellExecute = false

info.CreateNoWindow = true;

上面的行將阻止在 c# 中顯示
我使用以下代碼在后台運行 exe 並從 exe 讀取輸出:

字符串 ExeName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Curl.exe");
ProcessStartInfo Info = new ProcessStartInfo();
Info.UseShellExecute = false;
Info.FileName = ExeName;
Info.CreateNoWindow = true;
Info.Arguments = 參數;
Info.RedirectStandardOutput = true;
Info.WindowStyle = ProcessWindowStyle.Hidden;
進程 P = Process.Start(Info);
string OutPut = P.StandardOutput.ReadToEnd();
返回輸出;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM