【问题标题】:how to check if OpenOffice is installed programatically using c#如何使用 c# 检查 OpenOffice 是否以编程方式安装
【发布时间】:2010-10-21 06:23:46
【问题描述】:

如何检查 OpenOffice 是否使用 c# 以编程方式安装

【问题讨论】:

  • 哪个操作系统? Windows、Linux 还是其他?

标签: c# openoffice.org


【解决方案1】:
     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 个空格,使其成为代码的一部分。
  • 我的 LibreOffice 安装未在此处列出(可能我是通过 chocolatey.org 安装的)
【解决方案2】:

这里是获取默认程序的启动位置以打开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

【讨论】:

    【解决方案3】:

    和其他语言一样吗?在文件系统上的已知位置搜索启动 open office 的可执行文件?检查图书馆?解析“which openoffice”的输出?

    有很多选择,我想说其中大多数都不可靠。

    【讨论】:

    • 谢谢。得到了解决方案,我使用注册表搜索openoffice安装
    • @rajshades:发布您找到的解决方案并接受它作为正确答案
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-08
    • 1970-01-01
    • 2011-06-23
    • 1970-01-01
    • 2022-12-03
    • 1970-01-01
    相关资源
    最近更新 更多