如何使用C#编程来检查OpenOffice是否已安装

3
如何使用C#编程来检查OpenOffice是否已安装

哪个操作系统?Windows、Linux还是其他什么? - Doc Brown
3个回答

3
     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;
        }


    }

在声明 public bool IsOpenOfficeInstalled(){ 前面加上4个空格,使其成为代码的一部分。 - Alex Essilfie
我的LibreOffice安装在这里没有列出来(也许我是通过https://chocolatey.org/安装的)。 - habakuk

1
这里有一个解决方案,可以获取默认程序打开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

0

和其他语言一样吗?在文件系统中搜索已知位置以查找启动OpenOffice的可执行文件?检查库?解析“which openoffice”的输出?

有很多选项,我认为大多数选项都不可靠。


谢谢。我已经找到解决方案了,我使用注册表搜索了OpenOffice的安装位置。 - rajshades
@rajshades:发布你找到的解决方案并将其接受为正确答案。 - abatishchev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接