ProcessStartInfo.UseShellExecute 屬性


獲取或設置一個值,該值指示是否使用操作系統外殼程序啟動進程。

命名空間:System.Diagnostics
程序集:System(在 system.dll 中)

語法
 
 
 
public bool UseShellExecute { get; set; }
J#
 
/** @property */
public boolean get_UseShellExecute ()

/** @property */
public void set_UseShellExecute (boolean value)

 
public function get UseShellExecute () : boolean

public function set UseShellExecute (value : boolean)

 

 

屬性值

若要在啟動進程時使用外殼程序,則為  true;否則,直接從可執行文件創建進程。默認為  true
備注
 
 

將此屬性設置為 false 使您能夠重定向輸入流、輸出流和錯誤流。

Note注意

   如果 UserName 屬性不為 空引用(在 Visual Basic 中為 Nothing) 或不是一個空字符串,則 UseShellExecute 必須為 false,否則調用Process.Start(ProcessStartInfo) 方法時將引發 InvalidOperationException

使用操作系統外殼程序啟動進程時,您能夠使用 Process 組件啟動任何文檔(可以是任何與可執行文件關聯的、擁有默認打開操作的注冊文件類型),並對該文件執行操作(如打印)。當 UseShellExecute 為 false 時,使用 Process 組件僅能啟動可執行文件。

Note注意

如果將 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();


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM