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

发布于 2024-09-28 09:41:53 字数 38 浏览 0 评论 0原文

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

how to check if OpenOffice is installed programatically using c#

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

鼻尖触碰 2024-10-05 09:41:53
     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()
        {


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


    }
百善笑为先 2024-10-05 09:41:53

这是一个获取打开 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

Here is a solution that gets the startup location of the default program to open a odt file. As long as the file association has not been changed this works regardless of what version is installed.

(this is 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
你是暖光i 2024-10-05 09:41:53

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

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

Same as in any other language? Search the known locations on the file system for the executable that launches open office? Check for libraries? Parse the output of "which openoffice"?

There are lots of options, and I'd say that most of them would not be reliable.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文