private static bool TryGetJavaHome(RegistryView registryView, string vendor, string installation, out string javaHome)
        {
            javaHome = null;

            string javaKeyName = "SOFTWARE\\" + vendor + "\\" + installation;

            using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView))
            {
                using (RegistryKey javaKey = baseKey.OpenSubKey(javaKeyName))
                {
                    if (javaKey == null)
                    {
                        return(false);
                    }

                    object currentVersion = javaKey.GetValue("CurrentVersion");
                    if (currentVersion == null)
                    {
                        return(false);
                    }

                    using (var homeKey = javaKey.OpenSubKey(currentVersion.ToString()))
                    {
                        if (homeKey == null || homeKey.GetValue("JavaHome") == null)
                        {
                            return(false);
                        }

                        javaHome = homeKey.GetValue("JavaHome").ToString();
                        return(!string.IsNullOrEmpty(javaHome));
                    }
                }
            }
        }
Esempio n. 2
0
 internal RegistryKey(string name, RemoveType removeType, List <RegistryKey> keys, List <RegistryValue> values, Microsoft.Win32.RegistryView registryView)
 {
     KeyName       = name;
     _removeType   = removeType;
     Keys          = new RegistryKeyCollection(keys);
     Values        = new RegistryValueCollection(values);
     _registryView = registryView;
 }
Esempio n. 3
0
        private static RegistryKey ReadRegistryKey(XmlReader reader)
        {
            Microsoft.Win32.RegistryView registryView = Microsoft.Win32.RegistryView.Default;
            RemoveType           removeType           = RemoveType.No;
            string               name   = string.Empty;
            List <RegistryKey>   keys   = new List <RegistryKey>();
            List <RegistryValue> values = new List <RegistryValue>();

            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case KeyNameAttributeName:
                    name = reader.ReadContentAsString();
                    break;

                case KeyRegistryViewAttributeName:
                    registryView = reader.ReadContentAsEnum <Microsoft.Win32.RegistryView>();
                    break;

                case KeyRemoveTypeAttributeName:
                    removeType = reader.ReadContentAsEnum <RemoveType>();
                    break;
                }
            }

            reader.MoveToElement();

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.EndElement &&
                    string.Equals(KeyElementName, reader.Name))
                {
                    break;
                }
                if (reader.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                switch (reader.Name)
                {
                case KeyElementName:
                    RegistryKey registryKey = ReadRegistryKey(reader);
                    keys.Add(registryKey);
                    break;

                case ValueElementName:
                    RegistryValue registryValue = ReadRegistryValue(reader);
                    values.Add(registryValue);
                    break;
                }
            }
            RegistryKey registry = new RegistryKey(name, removeType, keys, values, registryView);

            return(registry);
        }
Esempio n. 4
0
        } // End Static Constructor

        public static string GetDefaultInstance()
        {
            try
            {
                if (System.Environment.OSVersion.Platform != System.PlatformID.Unix)
                {
                    Microsoft.Win32.RegistryView registryView = System.Environment.Is64BitOperatingSystem ?
                                                                Microsoft.Win32.RegistryView.Registry64 :
                                                                Microsoft.Win32.RegistryView.Registry32;

                    using (Microsoft.Win32.RegistryKey hklm = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, registryView))
                    {
                        Microsoft.Win32.RegistryKey instanceKey = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL", false);
                        if (instanceKey != null)
                        {
                            foreach (string instanceName in instanceKey.GetValueNames())
                            {
                                return(System.Environment.MachineName + @"\" + instanceName);
                            } // Next instanceName
                        }     // End if (instanceKey != null)
                    }         // End Using hklm
                }             // End if (System.Environment.OSVersion.Platform != System.PlatformID.Unix)

                /*
                 * // using Microsoft.SqlServer.Management.Smo.Wmi;
                 * System.Data.Common.DbDataSourceEnumerator
                 * System.Data.DataTable dt = System.Data.SqlDataSourceEnumerator.Instance.GetDataSources();
                 * foreach (System.Data.DataRow row in dt.Rows)
                 * {
                 *  foreach (System.Data.DataColumn col in dt.Columns)
                 *  {
                 *      System.Console.WriteLine("{0} = {1}", col.ColumnName, row[col]);
                 *  }
                 * }
                 *
                 * Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer mc =
                 *  new Microsoft.SqlServer.Management.Smo.Wmi.ManagedComputer();
                 *
                 * foreach (Microsoft.SqlServer.Management.Smo.Wmi.ServerInstance si in mc.ServerInstances)
                 * {
                 *  System.Console.WriteLine("The installed instance name is " + si.Name);
                 * }
                 */
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e);
                throw;
            }

            return(System.Environment.MachineName);
        } // End Function GetDefaultInstance
        private static bool TryGetJavaHome(string vendor, string installation, RegistryView registryView, out string javaHome)
        {
            Contract.Requires <ArgumentNullException>(vendor != null, "vendor");
            Contract.Requires <ArgumentNullException>(installation != null, "installation");
            Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(vendor));
            Contract.Requires <ArgumentException>(!string.IsNullOrEmpty(installation));

            javaHome = null;

            if (registryView == RegistryView.Registry64 && !Environment.Is64BitOperatingSystem)
            {
                // without this check, Registry64 defaults to returning values from the 32-bit registry.
                return(false);
            }

            string javaKeyName = "SOFTWARE\\" + vendor + "\\" + installation;

            using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView))
            {
                using (RegistryKey javaKey = baseKey.OpenSubKey(javaKeyName, RegistryKeyPermissionCheck.ReadSubTree))
                {
                    if (javaKey == null)
                    {
                        return(false);
                    }

                    object currentVersion = javaKey.GetValue("CurrentVersion");
                    if (currentVersion == null)
                    {
                        return(false);
                    }

                    using (var homeKey = javaKey.OpenSubKey(currentVersion.ToString()))
                    {
                        if (homeKey == null || homeKey.GetValue("JavaHome") == null)
                        {
                            return(false);
                        }

                        javaHome = homeKey.GetValue("JavaHome").ToString();
                        return(!string.IsNullOrEmpty(javaHome));
                    }
                }
            }
        }
Esempio n. 6
0
        private static bool TryFindJavaPath(string vendor, string installation, string fileName, RegistryView registryView, out string javaBinary)
        {
            javaBinary = null;

            try
            {
                string javaHome;
                if (TryGetJavaHome(vendor, installation, registryView, out javaHome))
                {
                    string binary = Path.Combine(javaHome, "bin", fileName);
                    if (!File.Exists(binary))
                        return false;

                    javaBinary = binary;
                    return true;
                }

                return false;
            }
            catch (SecurityException)
            {
                return false;
            }
        }
        private static bool TryGetJavaHome(RegistryView registryView, string vendor, string installation, out string javaHome)
        {
            javaHome = null;

            string javaKeyName = "SOFTWARE\\" + vendor + "\\" + installation;
            using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView))
            {
                using (RegistryKey javaKey = baseKey.OpenSubKey(javaKeyName))
                {
                    if (javaKey == null)
                        return false;

                    object currentVersion = javaKey.GetValue("CurrentVersion");
                    if (currentVersion == null)
                        return false;

                    using (var homeKey = javaKey.OpenSubKey(currentVersion.ToString()))
                    {
                        if (homeKey == null || homeKey.GetValue("JavaHome") == null)
                            return false;

                        javaHome = homeKey.GetValue("JavaHome").ToString();
                        return !string.IsNullOrEmpty(javaHome);
                    }
                }
            }
        }
Esempio n. 8
0
 public IRegistryKey OpenRemoteBaseKey(Microsoft.Win32.RegistryHive hKey, string machineName, Microsoft.Win32.RegistryView view)
 {
     return(RegistryKey.Wrap(Microsoft.Win32.RegistryKey.OpenRemoteBaseKey(hKey, machineName, view)));
 }
Esempio n. 9
0
 public IRegistryKey OpenBaseKey(Microsoft.Win32.RegistryHive hKey, Microsoft.Win32.RegistryView view)
 {
     return(RegistryKey.Wrap(Microsoft.Win32.RegistryKey.OpenBaseKey(hKey, view)));
 }
Esempio n. 10
0
 public IRegistryKey FromHandle(Microsoft.Win32.SafeHandles.SafeRegistryHandle handle, Microsoft.Win32.RegistryView view)
 {
     return(RegistryKey.Wrap(Microsoft.Win32.RegistryKey.FromHandle(handle, view)));
 }
Esempio n. 11
0
 public static Microsoft.Win32.RegistryKey OpenRemoteBaseKey(Microsoft.Win32.RegistryHive hKey, string machineName, Microsoft.Win32.RegistryView view)
 {
     throw null;
 }
Esempio n. 12
0
 public static Microsoft.Win32.RegistryKey OpenBaseKey(Microsoft.Win32.RegistryHive hKey, Microsoft.Win32.RegistryView view)
 {
     throw null;
 }
Esempio n. 13
0
 public static string CreateStoragePath(Microsoft.Win32.RegistryHive hive, Microsoft.Win32.RegistryView view, string path, string name)
 {
     return($"reg:\\\\{view}:{hive}\\{path}\\{name}");
 }
        private static bool TryFindJavaPath(string vendor, string installation, string fileName, RegistryView registryView, out string javaBinary)
        {
            javaBinary = null;

            try
            {
                string javaHome;
                if (TryGetJavaHome(vendor, installation, registryView, out javaHome))
                {
                    string binary = Path.Combine(javaHome, "bin", fileName);
                    if (!File.Exists(binary))
                    {
                        return(false);
                    }

                    javaBinary = binary;
                    return(true);
                }

                return(false);
            }
            catch (SecurityException)
            {
                return(false);
            }
        }
Esempio n. 15
0
        private static bool TryGetJavaHome(string vendor, string installation, RegistryView registryView, out string javaHome)
        {
            Contract.Requires<ArgumentNullException>(vendor != null, "vendor");
            Contract.Requires<ArgumentNullException>(installation != null, "installation");
            Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(vendor));
            Contract.Requires<ArgumentException>(!string.IsNullOrEmpty(installation));

            javaHome = null;

            if (registryView == RegistryView.Registry64 && !Environment.Is64BitOperatingSystem)
            {
                // without this check, Registry64 defaults to returning values from the 32-bit registry.
                return false;
            }

            string javaKeyName = "SOFTWARE\\" + vendor + "\\" + installation;
            using (var baseKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, registryView))
            {
                using (RegistryKey javaKey = baseKey.OpenSubKey(javaKeyName, RegistryKeyPermissionCheck.ReadSubTree))
                {
                    if (javaKey == null)
                        return false;

                    object currentVersion = javaKey.GetValue("CurrentVersion");
                    if (currentVersion == null)
                        return false;

                    using (var homeKey = javaKey.OpenSubKey(currentVersion.ToString()))
                    {
                        if (homeKey == null || homeKey.GetValue("JavaHome") == null)
                            return false;

                        javaHome = homeKey.GetValue("JavaHome").ToString();
                        return !string.IsNullOrEmpty(javaHome);
                    }
                }
            }
        }
Esempio n. 16
0
 public static Microsoft.Win32.RegistryKey FromHandle(Microsoft.Win32.SafeHandles.SafeRegistryHandle handle, Microsoft.Win32.RegistryView view)
 {
     return(default(Microsoft.Win32.RegistryKey));
 }
Esempio n. 17
0
 public static Microsoft.Win32.RegistryKey OpenBaseKey(Microsoft.Win32.RegistryHive hKey, Microsoft.Win32.RegistryView view)
 {
     return(default(Microsoft.Win32.RegistryKey));
 }
Esempio n. 18
0
 public static Microsoft.Win32.RegistryKey FromHandle(Microsoft.Win32.SafeHandles.SafeRegistryHandle handle, Microsoft.Win32.RegistryView view)
 {
     throw null;
 }