views:

53

answers:

2

how to check if OpenOffice is installed programatically using c#

A: 

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.

OJ
thanks. got the soltuion, i used registry to search openoffice instalation
rajshades
@rajshades: Post the solution you found and accept it as correct answer
abatishchev
+2  A: 
     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;
        }


    }
rajshades
Place 4 spaces before the declaration `public bool IsOpenOfficeInstalled(){` so it becomes part of the code.
Alex Essilfie