ProcessStartInfo.UseShellExecute 屬性
獲取或設(shè)置一個(gè)值,該值指示是否使用操作系統(tǒng)外殼程序啟動(dòng)進(jìn)程。
命名空間: System.Diagnostics
程序集: System(在 System.dll 中)
屬性值
類型:System.Boolean若要在啟動(dòng)進(jìn)程時(shí)使用外殼程序,則為 true;否則,直接從可執(zhí)行文件創(chuàng)建進(jìn)程。默認(rèn)為 true。
備注
將此屬性設(shè)置為 false 使您能夠重定向輸入流、輸出流和錯(cuò)誤流。
注意:
如果 UserName屬性不為 nullNothingnullptrnull 引用(在Visual Basic 中為 Nothing) 或不是一個(gè)空字符串,則 UseShellExecute 必須為 false,否則調(diào)用Process..::.Start(ProcessStartInfo)方法時(shí)將引發(fā)InvalidOperationException。
使用操作系統(tǒng)外殼程序啟動(dòng)進(jìn)程時(shí),可以使用Process組件啟動(dòng)任何文檔(可以是與可執(zhí)行文件關(guān)聯(lián)的、具有默認(rèn)打開操作的任何注冊(cè)文件類型),并對(duì)該文件執(zhí)行操作(如打?。?。如果UseShellExecute 為 false,則只能使用 Process組件啟動(dòng)可執(zhí)行文件。
注意:
如果將 ErrorDialog屬性設(shè)置為 true,則 UseShellExecute 必須為 true。
WorkingDirectory屬性的行為在 UseShellExecute 為 true 并當(dāng)UseShellExecute 為 false 時(shí)是不同的。當(dāng) UseShellExecute 為 true時(shí),WorkingDirectory屬性指定可執(zhí)行文件的位置。如果WorkingDirectory是空字符串,則認(rèn)為當(dāng)前目錄包含可執(zhí)行文件。
當(dāng) UseShellExecute 為 false 時(shí),不使用WorkingDire--ctory屬性查找可執(zhí)行文件。相反,該屬性會(huì)由已啟動(dòng)的進(jìn)程使用,并且只在新進(jìn)程的上下文中有意義。
示例
C#
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();
愛華網(wǎng)



