2012-08-16 113 views
2

我正在爲我們的組件創建安裝包。其中一個必備條件是具有最低版本8i的oracle客戶機應安裝在目標機器上。我怎樣才能做到這一點?如何檢查已安裝或未安裝的Oracle客戶端作爲組件安裝的先決條件

我稱爲下方張貼

What's the best way to determine which version of Oracle client I'm running?

由具有此我寫的以下動作。我試圖用tnsping實用程序來檢查。

string result = string.Empty; 
       System.Diagnostics.ProcessStartInfo proces = new System.Diagnostics.ProcessStartInfo("tnsping.exe"); 
       proces.RedirectStandardOutput = true; 
       proces.CreateNoWindow = true; 
       proces.UseShellExecute = false; 
       System.Diagnostics.Process bufor; 
       bufor = System.Diagnostics.Process.Start(proces); 
       System.IO.StreamReader Output = bufor.StandardOutput; 
       bufor.WaitForExit(2000); 
       if (bufor.HasExited) 
       { 
        result = Output.ReadToEnd(); 
        result = result.ToLower(); 
        if (result.Contains("64-bit")) 
        { 
         is64BitOracleClient = true; 
        } 

        int verINT = result.IndexOf("version", 0, result.Length); 
        if (verINT != null) 
        { 
         version = result.Substring(verINT + "version".Length + 1, 8); 
         Version installedVersion = new Version(version); 
         Version expectedVersion = new Version("8.1.7.0"); 
         if (installedVersion >= expectedVersion) 
         { 
          isVersionMatched = true; 
         } 
        } 
       } 

這裏我正在執行工具tnsping。如果我收到異常在

bufor = System.Diagnostics.Process.Start(proces); 

我斷定Oracle客戶端沒有安裝。

如果這個工具是可用的,我是從這個結果得到以下結果

TNS Ping Utility for 64-bit Windows: Version 11.2.0.1.0 - Production on 16-AUG-2 
012 06:27:58 

,我解析版本和驗證相同。

這是正確的做法嗎?還有其他更好的方法嗎?

回答

0

我沒有更好的答案給你,但我在我的應用程序中使用了你的解決方案,它按預期工作。

相關問題