Ejemplo n.º 1
0
        /// <summary>
        /// /// ORACLE DETECTION
        /// 1. Check if ORACLE_HOME exists in the 64 or 32 bit registry
        ///   a. How many clients we have installed?
        /// 2. Check if ORACLE_HOME env. variable exists
        /// 3. Instant Client (i.e. no sqlplus) from 10.2.0.3 up can run %ORACLE_HOME%/genezi -v to get client version.
        /// Available in regular client install but useful in Instant Client.
        /// If no registry entries exist Instant Client must be added to %PATH% otherwise it won't work, so we execute 'genezi -v' directly
        /// </summary>
        public OracleClientsHelper()
        {
            try
            {
                //Check if x32 bit Oracle client exist in registries (\WOW6432Node\SOFTWARE\Oracle on x64 machines)
                RegistryKey rk = Registry.LocalMachine.OpenSubKey(keyPath);
                if (rk != null)
                {
                    GetOracleClients(32, rk.GetSubKeyNames().ToList <String>());
                }

                //If the system is x64, check also the x64 registries registries \SOFTWARE\Oracle
                if (OSCollectorHelper.is64BitOperatingSystem)
                {
                    List <string> oracleKeyNames = RegistryWrapper.GetSubKeyNames(RegHive.LocalMachine, keyPath, RegSAM.WOW64_64Key);
                    GetOracleClients(64, oracleKeyNames);
                }

                //If nothing was found in registry, check for Instant client
                if (clients.Count == 0)
                {
                    //Check for instant client
                    //Check if ORACLE_HOME env. variable exists
                    string home = Environment.GetEnvironmentVariable("ORACLE_HOME");

                    //If ORACLE_HOME exists run 'genezi -v' in that dir, otherwise simply run it hoping genezi.exe is in the %PATH%
                    string command = (home != null && Directory.Exists(home)) ? home + @"\genezi -v" : "genezi -v";

                    string geneziInfo = Helper.ExecuteCMDCommand(command);

                    if (geneziInfo.StartsWith("Client"))
                    {
                        output.Append(geneziInfo.Split('\r')[0] + " at " + home);
                    }
                }
                else
                {
                    output.Append(clients.Count + " client(s) found: " + Html.br);
                    foreach (var client in clients)
                    {
                        output.Append(client.ToString() + Html.br);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex.ToString());
            }
        }
Ejemplo n.º 2
0
        public static List <InstalledProgram> GetListOfInstalledPrograms()
        {
            string uninstallerKeyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall";

            //1. Get the products from 32bit Uninstaller @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
            installedProgramsList.AddProductsFromUninstallerKey(RegHive.LocalMachine, uninstallerKeyPath, RegSAM.WOW64_32Key);
            //count = installedProductsList.Count;
            //Logger.Debug(count + @" products found in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");

            //2. Get the products from 64bit Uninstaller @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
            installedProgramsList.AddProductsFromUninstallerKey(RegHive.LocalMachine, uninstallerKeyPath, RegSAM.WOW64_64Key);
            //count = installedProductsList.Count - count;
            //Logger.Debug(count + @" products found in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
            //count = installedProductsList.Count;

            //3. Get the products from HKEY_USERS\<user-sid>\Software\Microsoft\Windows\CurrentVersion\Uninstall
            string        keyPath  = @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList";
            List <string> userKeys = RegistryWrapper.GetSubKeyNames(RegHive.LocalMachine, keyPath, RegSAM.WOW64_64Key);

            Logger.Debug(userKeys.Count + " user keys found in " + keyPath);

            if (userKeys != null)
            {
                foreach (var userKey in userKeys)
                {
                    installedProgramsList.AddProductsFromUninstallerKey(RegHive.Users, userKey + "\\" + uninstallerKeyPath, RegSAM.WOW64_64Key);
                    count = installedProgramsList.Count - count;
                    Logger.Debug(count + " products found in HKEY_USERS\\" + userKey + "\\" + uninstallerKeyPath);
                    count = installedProgramsList.Count;
                }
            }

            //4. Get the products from "Software\Microsoft\Windows\CurrentVersion\Installer\UserData\<user-sid>\Products\<product-code>\InstallProperties"
            keyPath  = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData";
            userKeys = RegistryWrapper.GetSubKeyNames(RegHive.LocalMachine, keyPath, RegSAM.WOW64_64Key);
            if (userKeys != null)
            {
                foreach (var userKey in userKeys)
                {
                    if (userKey != "S-1-5-18")
                    {
                        //Get the products from i.e. "Software\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\<product-code>\InstallProperties"
                        keyPath = @"Software\Microsoft\Windows\CurrentVersion\Installer\UserData\" + userKey + @"\Products\";
                        List <string> productKeys = RegistryWrapper.GetSubKeyNames(RegHive.LocalMachine, keyPath, RegSAM.WOW64_64Key);
                        if (productKeys != null)
                        {
                            foreach (var productKey in productKeys)
                            {
                                string key             = keyPath + productKey + @"\InstallProperties";
                                string systemComponent = RegistryWrapper.GetRegKey(RegHive.LocalMachine, key, RegSAM.WOW64_64Key, "SystemComponent");
                                if (systemComponent != "1")
                                {
                                    string uninstallString = RegistryWrapper.GetRegKey(RegHive.LocalMachine, key, RegSAM.WOW64_64Key, "UninstallString");
                                    string displayName     = RegistryWrapper.GetRegKey(RegHive.LocalMachine, key, RegSAM.WOW64_64Key, "DisplayName");
                                    string displayVersion  = RegistryWrapper.GetRegKey(RegHive.LocalMachine, key, RegSAM.WOW64_64Key, "DisplayVersion");
                                    string installDate     = RegistryWrapper.GetRegKey(RegHive.LocalMachine, key, RegSAM.WOW64_64Key, "InstallDate");

                                    if (displayName != null && displayName != "")
                                    {
                                        var installedProduct = new InstalledProgram(displayName, displayVersion, uninstallString, installDate);
                                        if (!installedProgramsList.Contains(installedProduct))
                                        {
                                            installedProgramsList.Add(installedProduct);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    count = installedProgramsList.Count - count;
                    Logger.Debug(count + " products found in HKEY_LOCAL_MACHINE\\" + keyPath);
                    count = installedProgramsList.Count;
                }
            }
            // Add some logs for debugging
            if (Logger.level == (int)Logger.Level.DEBUG)
            {
                Logger.Debug("Products after Sort");
                int i = 1;
                foreach (var p in installedProgramsList)
                {
                    Logger.Debug(i + " " + p);
                    i++;
                }
            }
            return(installedProgramsList);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Method to get the installation folder to JDK or JRE
        /// 1. Check 64bit registry
        /// </summary>
        /// <param name="product"></param>
        /// <param name="registryView">32 or 64</param>
        /// <returns></returns>
        private List <String> GetPathsToJava(string product, string registryView = null)
        {
            List <String> javaPaths = new List <string>();
            List <string> keys      = new List <string>();

            //String key = String.Empty;
            try
            {
                //search the 64bit registry (WOW6432Node) if we are on 64bit OS
                if (registryView == "64" && OSCollectorHelper.is64BitOperatingSystem)
                {
                    keys = RegistryWrapper.GetSubKeyNames(RegHive.LocalMachine, keyPath + product, RegSAM.WOW64_64Key);
                    if (keys != null)
                    {
                        Logger.Info("Found " + keys.Count + " keys in " + registryView + " registry " + keyPath);
                        foreach (string key in keys)
                        {
                            Logger.Info("Getting 'JavaHome' value from " + keyPath + product + "\\" + key);
                            javaPaths.Add(RegistryWrapper.GetRegKey64(RegHive.LocalMachine, keyPath + product + "\\" + key, "JavaHome"));
                        }
                    }
                    else
                    {
                        Logger.Info("No JAVA found in " + registryView + "bit registry " + keyPath + product);
                        return(null);
                    }
                }
                //search the 32bit registrys
                else if (registryView == "32")
                {
                    keys = RegistryWrapper.GetSubKeyNames(RegHive.LocalMachine, keyPath + product, RegSAM.WOW64_32Key);
                    if (keys != null)
                    {
                        Logger.Info("Found " + keys.Count + " keys in " + registryView + " registry " + keyPath);
                        foreach (string key in keys)
                        {
                            Logger.Info("Getting 'JavaHome' value from " + keyPath + product + "\\" + key);
                            javaPaths.Add(RegistryWrapper.GetRegKey32(RegHive.LocalMachine, keyPath + product + "\\" + key, "JavaHome"));
                        }
                    }
                    else
                    {
                        Logger.Info("No JAVA found in " + registryView + "bit registry " + keyPath + product);
                        return(null);
                    }
                }

                //remove the duplicate entries
                return(javaPaths.Distinct().ToList());
            }
            catch (NullReferenceException nre)
            {
                Logger.Info(nre.ToString());
                return(null);
            }
            catch (Exception ex)
            {
                Logger.Info(ex.ToString());
                return(null);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Method to append the none-duplicated products from Uninstaller key
        /// We do this by iterating through the 64 and 32 bit Uninstall key @"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        /// and @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall".
        /// Ignore all SystemComponent key names that have value of 1
        /// Then we iterate through all user keys HKEY_USERS\user-sid\Software\Microsoft\Windows\CurrentVersion\Uninstall
        /// Then we add all none-duplicated products from @"Software\Microsoft\Windows\CurrentVersion\Installer\UserData\user-sid\Products\product-code\InstallProperties"
        /// </summary>
        /// <param name="tempInstalledProducts"></param>
        /// <param name="inHive"></param>
        /// <param name="uninstallerKeyPath"></param>
        /// <param name="in64or32key"></param>
        /// <returns></returns>
        public static List <InstalledProgram> AddProductsFromUninstallerKey(this List <InstalledProgram> tempInstalledProducts, UIntPtr inHive, string uninstallerKeyPath, RegSAM in64or32key)
        {
            var regex        = new Regex("KB[0-9]{5,7}$");
            int updatesCount = 0;

            List <string> subkeyNames = RegistryWrapper.GetSubKeyNames(inHive, uninstallerKeyPath, in64or32key);

            if (subkeyNames != null)
            {
                foreach (var subkeyName in subkeyNames)
                {
                    // Check only keys like {CFEF48A8-BFB8-3EAC-8BA5-DE4F8AA267CE}
                    // but not {CFEF48A8-BFB8-3EAC-8BA5-DE4F8AA267CE}.KB2504637 which are updates
                    if (!regex.Match(subkeyName).Success)
                    {
                        string SystemComponent = RegistryWrapper.GetRegKey(inHive, uninstallerKeyPath + "\\" + subkeyName, in64or32key, "SystemComponent");
                        if (SystemComponent != "1")
                        {
                            string Windowsinstaller = RegistryWrapper.GetRegKey(inHive, uninstallerKeyPath + "\\" + subkeyName, in64or32key, "Windowsinstaller");
                            if (Windowsinstaller != "1")
                            {
                                //Make sure we are not dealing with a patch or an update
                                string releaseType   = RegistryWrapper.GetRegKey(inHive, uninstallerKeyPath + "\\" + subkeyName, in64or32key, "ReleaseType");
                                string parentKeyName = RegistryWrapper.GetRegKey(inHive, uninstallerKeyPath + "\\" + subkeyName, in64or32key, "ParentKeyName");

                                if (parentKeyName != null)
                                {
                                    if (parentKeyName != "" || releaseType == "Security Update" || releaseType == "Update Rollup" || releaseType == "Hotfix")
                                    {
                                        updatesCount++;
                                    }
                                }

                                if (parentKeyName == null)
                                {
                                    string uninstallString = RegistryWrapper.GetRegKey(inHive, uninstallerKeyPath + "\\" + subkeyName, in64or32key, "UninstallString");
                                    if (uninstallString != null)
                                    {
                                        string displayName    = RegistryWrapper.GetRegKey(inHive, uninstallerKeyPath + "\\" + subkeyName, in64or32key, "DisplayName");
                                        string displayVersion = RegistryWrapper.GetRegKey(inHive, uninstallerKeyPath + "\\" + subkeyName, in64or32key, "DisplayVersion");
                                        string installDate    = RegistryWrapper.GetRegKey(inHive, uninstallerKeyPath + "\\" + subkeyName, in64or32key, "InstallDate");

                                        if (displayName != null && displayName != "")
                                        {
                                            var product = new InstalledProgram(displayName, displayVersion, uninstallString, installDate);
                                            if (!tempInstalledProducts.Contains(product))
                                            {
                                                tempInstalledProducts.Add(product);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                string productId   = GetInstallerKeyNameFromGuid(subkeyName);
                                string productKey  = @"Software\Classes\Installer\Products\" + productId;
                                string productName = RegistryWrapper.GetRegKey(inHive, productKey, RegSAM.WOW64_64Key, "ProductName");
                                if (productName != null)
                                {
                                    string displayVersion  = RegistryWrapper.GetRegKey(inHive, uninstallerKeyPath + "\\" + subkeyName, in64or32key, "DisplayVersion");
                                    string uninstallString = RegistryWrapper.GetRegKey(inHive, uninstallerKeyPath + "\\" + subkeyName, in64or32key, "UninstallString");
                                    string installDate     = RegistryWrapper.GetRegKey(inHive, uninstallerKeyPath + "\\" + subkeyName, in64or32key, "InstallDate");

                                    var product = new InstalledProgram(productName, displayVersion, uninstallString, installDate);
                                    if (!tempInstalledProducts.Contains(product))
                                    {
                                        tempInstalledProducts.Add(product);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(tempInstalledProducts);
        }