2014-03-27 76 views
2

我的wpf應用程序調用python腳本來生成稍後顯示在UI中的輸出。爲避免應用程序崩潰,如果未在用戶系統上安裝python,我需要執行檢查。目前,我已經實現了使用以下WPF檢查系統上是否安裝了python

ProcessStartInfo start = new ProcessStartInfo(); 
start.FileName = @"cmd.exe"; // Specify exe name. 
start.Arguments = "python --version"; 
start.UseShellExecute = false; 
start.RedirectStandardError = true; 

using (Process process = Process.Start(start)) 
     { 
      using (StreamReader reader = process.StandardError) 
      { 
       string result = reader.ReadToEnd(); 
       MessageBox.Show(result); 
      } 
     } 

這做工作,但促使CMD黑色窗口這是非常不希望的瞬間外觀。是否有解決方法來實現此目的或修復以避免出現窗口?

+2

也許add start.CreateNoWindow = true; ? – Dave3of5

+1

可能的複製:http://stackoverflow.com/questions/5377423/hide-console-window-from-process-start-c-sharp – clcto

回答

0

試試這個:或者

ProcessStartInfo start = new ProcessStartInfo(); 
start.FileName = @"cmd.exe"; // Specify exe name. 
start.Arguments = "python --version"; 
start.UseShellExecute = false; 
start.RedirectStandardError = true; 
start.CreateNoWindow = true; 

using (Process process = Process.Start(start)) 
     { 
      using (StreamReader reader = process.StandardError) 
      { 
       string result = reader.ReadToEnd(); 
       MessageBox.Show(result); 
      } 
     } 
5

,你可以檢查註冊表中的關鍵HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\Python.exe

默認值。這可以說是更可靠的不僅僅是試圖運行python.exe,因爲Python的安裝程序並不總是更新PATH變量。

+0

如何檢查?我有很多,但徒勞 –

+0

你知道如何以編程方式讀取註冊表嗎? Google「C#讀取註冊表」。 –

相關問題