ProcessStartInfo.UseShellExecute 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定值,表示是否要使用作業系統 Shell 來啟動處理序。
public:
property bool UseShellExecute { bool get(); void set(bool value); };
public bool UseShellExecute { get; set; }
member this.UseShellExecute : bool with get, set
Public Property UseShellExecute As Boolean
屬性值
如果在啟動處理序時使用 Shell,則為 true
,如果處理序應直接從可執行檔建立,則為 false
。 預設值為 true
.NET Framework 應用程式和 false
.NET Core 應用程式。
例外狀況
嘗試在通用 Windows 平台 (UWP) App 上將值設定為 true
。
範例
// Run "cl.exe /cld stdstr.cpp /link /out:sample.exe". UseShellExecute is false because we're specifying
// an executable directly and in this case depending on it being in a PATH folder. By setting
// RedirectStandardOutput to true, the output of cl.exe is directed to the Process.StandardOutput stream
// which is then displayed in this console window directly.
Process^ compiler = gcnew Process;
compiler->StartInfo->FileName = "cl.exe";
compiler->StartInfo->Arguments = "/clr stdstr.cpp /link /out:sample.exe";
compiler->StartInfo->UseShellExecute = false;
compiler->StartInfo->RedirectStandardOutput = true;
compiler->Start();
Console::WriteLine( compiler->StandardOutput->ReadToEnd() );
compiler->WaitForExit();
// Run "csc.exe /r:System.dll /out:sample.exe stdstr.cs". UseShellExecute is false because we're specifying
// an executable directly and in this case depending on it being in a PATH folder. By setting
// RedirectStandardOutput to true, the output of csc.exe is directed to the Process.StandardOutput stream
// which is then displayed in this console window directly.
using (Process compiler = new Process())
{
compiler.StartInfo.FileName = "csc.exe";
compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs";
compiler.StartInfo.UseShellExecute = false;
compiler.StartInfo.RedirectStandardOutput = true;
compiler.Start();
Console.WriteLine(compiler.StandardOutput.ReadToEnd());
compiler.WaitForExit();
}
' Run "vbc.exe /reference:Microsoft.VisualBasic.dll /out:sample.exe stdstr.vb". UseShellExecute is False
' because we're specifying an executable directly and in this case depending on it being in a PATH folder.
' By setting RedirectStandardOutput to True, the output of csc.exe is directed to the Process.StandardOutput
' stream which is then displayed in this console window directly.
Using compiler As New Process()
compiler.StartInfo.FileName = "vbc.exe"
compiler.StartInfo.Arguments = "/reference:Microsoft.VisualBasic.dll /out:sample.exe stdstr.vb"
compiler.StartInfo.UseShellExecute = False
compiler.StartInfo.RedirectStandardOutput = True
compiler.Start()
Console.WriteLine(compiler.StandardOutput.ReadToEnd())
compiler.WaitForExit()
End Using
備註
將此屬性設定為 false
可讓您重新導向輸入、輸出和錯誤資料流程。
此內容中的 「shell」 這個字 () UseShellExecute
是指類似 Windows 殼層) 的 (圖形殼層,而不是命令殼層 (, bash
或 sh
) ,讓使用者啟動圖形應用程式或開啟檔。
注意
UseShellExecutefalse
如果 UserName 屬性不是 null
或空字串,或是 InvalidOperationException 呼叫 方法時 Process.Start(ProcessStartInfo) ,必須擲回 。
當您使用作業系統殼層來啟動處理常式時,您可以啟動任何檔 (這是與具有預設開啟動作的可執行檔相關聯的任何已註冊檔案類型,) 並使用 物件對檔案執行作業, Process 例如列印。 當 為 false
時 UseShellExecute ,您只能使用 Process 物件啟動可執行檔。
注意
UseShellExecute如果您將 ErrorDialog 屬性設定為 true
,就必須是 true
。
WorkingDirectory
屬性 WorkingDirectory 的行為會根據 屬性的值 UseShellExecute 而有所不同。 當 為 true
時 UseShellExecute , WorkingDirectory 屬性會指定可執行檔的位置。 如果 WorkingDirectory 是空字串,則會假設目前目錄包含可執行檔。
當 為 false
時 UseShellExecute , WorkingDirectory 屬性不會用來尋找可執行檔。 相反地,它只會由啟動的進程使用,而且只在新進程的內容中具有意義。 當 為 false
時 UseShellExecute , FileName 屬性可以是可執行檔的完整路徑,或是系統嘗試在環境變數所指定資料夾中尋找的 PATH
簡單可執行檔名稱。 搜尋路徑的解譯取決於作業系統。 如需詳細資訊,請在命令提示字元中輸入 HELP PATH
或 man sh
。
適用於
另請參閱
意見反應
提交並檢視相關的意見反應