2010-10-21 143 views

回答

0

同任何其他語言?搜索文件系統上的已知位置以查找啓動開放式辦公室的可執行文件?檢查圖書館?解析「哪個openoffice」的輸出?

有很多選擇,我會說,他們中的大多數不會是可靠的。

+0

謝謝。得到解散,我用註冊表來搜索openoffice instalation – rajshades 2010-10-21 07:02:21

+0

@rajshades:發佈你找到的解決方案,並接受它作爲正確的答案 – abatishchev 2010-10-21 08:09:10

2
 public bool isOpenofficeInstalled() 
     { 


     //The registry key: 
     string SoftwareKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; 
     using (RegistryKey rk = Registry.LocalMachine.OpenSubKey(SoftwareKey)) 
     { 
      bool flag = false; 
      //Let's go through the registry keys and get the info we need: 
      foreach (string skName in rk.GetSubKeyNames()) 
      { 
       using (RegistryKey sk = rk.OpenSubKey(skName)) 
       { 
        try 
        { 
         //If the key has value, continue, if not, skip it: 
         // if (((sk.GetValue("DisplayName")).ToString() == "OpenOffice.org 3.2")) 
         if((sk.GetValue("DisplayName")).ToString() == "OpenOffice.org 3.2") 
         { 

          flag = true; 
          ////install location ? 
          //if (sk.GetValue("InstallLocation") == null) 
          // Software += sk.GetValue("DisplayName") + " - Install path not known\n"; //Nope, not here. 
          //else 
          // Software += sk.GetValue("DisplayName") + " - " + sk.GetValue("InstallLocation") + "\n"; //Yes, here it is... 
         } 
        } 
        catch (Exception) 
        { 

        } 
       } 
      } 
      return flag; 
     } 


    } 
+0

在聲明之前放置4個空格'public bool IsOpenOfficeInstalled(){'所以它成爲代碼的一部分。 – 2010-10-21 08:36:44

+0

我的LibreOffice安裝沒有在這裏列出(也許我通過https://chocolatey.org/安裝了它) – habakuk 2017-03-16 14:52:01

0

這是一個解決方案,獲取默認程序的啓動位置來打開一個odt文件。只要文件關聯沒有被更改,無論安裝了什麼版本,這都可以工作。

(這是VB.NET)

Dim odt = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(".odt") 
Dim linkedValue = odt.GetValue("") 
Dim linkedKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(linkedValue) 
Dim openWith = linkedKey.OpenSubKey("Shell\Open\Command").GetValue("") 
Dim O As String = CStr(openWith) 

If O.Contains("swriter.exe") Then 
// proceed with code 
Else 
// error message 
End If 
相關問題