獲取或設置一個值,該值指示是否使用操作系統外殼程序啟動進程。
命名空間:System.Diagnostics
程序集:System(在 system.dll 中)
將此屬性設置為 false 使您能夠重定向輸入流、輸出流和錯誤流。
![]() |
---|
如果 UserName 屬性不為 空引用(在 Visual Basic 中為 Nothing) 或不是一個空字符串,則 UseShellExecute 必須為 false,否則調用Process.Start(ProcessStartInfo) 方法時將引發 InvalidOperationException。 |
使用操作系統外殼程序啟動進程時,您能夠使用 Process 組件啟動任何文檔(可以是任何與可執行文件關聯的、擁有默認打開操作的注冊文件類型),並對該文件執行操作(如打印)。當 UseShellExecute 為 false 時,使用 Process 組件僅能啟動可執行文件。
![]() |
---|
如果將 ErrorDialog 屬性設置為 true,則 UseShellExecute 必須為 true。 |
WorkingDirectory 屬性的行為在 UseShellExecute 為 true 並當 UseShellExecute 為 false 時是不同的。當 UseShellExecute 為 true時,WorkingDirectory 屬性指定可執行文件的位置。如果 WorkingDirectory 是空字符串,則認為當前目錄包含可執行文件。
當 UseShellExecute 為 false 時,不使用 WorkingDirectory 屬性查找可執行文件。相反,它被已啟動的進程使用,並且只在新進程的上下文中有意義。
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();