ReadGuidFromKey() public static method

public static ReadGuidFromKey ( RegistryKey rootKey, string keyName, string valueName ) : System.Guid
rootKey Microsoft.Win32.RegistryKey
keyName string
valueName string
return System.Guid
示例#1
0
        private void LoadFromKey(RegistryKey key)
        {
            string name = key.GetValue(null) as string;

            if (!String.IsNullOrWhiteSpace(name))
            {
                Name = COMUtilities.DemangleWinRTName(name.ToString());
                CacheIidToName(Iid, Name);
            }
            else
            {
                Name = Iid.FormatGuidDefault();
            }

            ProxyClsid = COMUtilities.ReadGuidFromKey(key, "ProxyStubCLSID32", null);
            NumMethods = COMUtilities.ReadIntFromKey(key, "NumMethods", null);

            if (NumMethods < 3)
            {
                NumMethods = 3;
            }

            TypeLib        = COMUtilities.ReadGuidFromKey(key, "TypeLib", null);
            TypeLibVersion = COMUtilities.ReadStringFromKey(key, "TypeLib", "Version");
            Base           = COMUtilities.ReadStringFromKey(key, "BaseInterface", null);
            if (Base.Length == 0)
            {
                Base = "IUnknown";
            }
        }
示例#2
0
        private void LoadProgIDs(RegistryKey rootKey)
        {
            m_progids        = new SortedDictionary <string, COMProgIDEntry>();
            m_progidsbyclsid = new Dictionary <Guid, List <COMProgIDEntry> >();

            string[] subkeys = rootKey.GetSubKeyNames();
            foreach (string key in subkeys)
            {
                try
                {
                    using (RegistryKey regKey = rootKey.OpenSubKey(key))
                    {
                        Guid clsid = COMUtilities.ReadGuidFromKey(regKey, "CLSID", null);
                        if (clsid != Guid.Empty)
                        {
                            COMProgIDEntry entry = new COMProgIDEntry(key, clsid, regKey);
                            m_progids.Add(key, entry);
                            if (!m_progidsbyclsid.ContainsKey(clsid))
                            {
                                m_progidsbyclsid[clsid] = new List <COMProgIDEntry>();
                            }

                            m_progidsbyclsid[clsid].Add(entry);
                        }
                    }
                }
                catch (FormatException e)
                {
                    System.Diagnostics.Debug.WriteLine(e.ToString());
                }
            }
        }
示例#3
0
        private void LoadProgIDs(RegistryKey rootKey)
        {
            Dictionary <string, COMProgIDEntry> progids = new Dictionary <string, COMProgIDEntry>(StringComparer.OrdinalIgnoreCase);

            string[] subkeys = rootKey.GetSubKeyNames();
            foreach (string key in subkeys)
            {
                try
                {
                    using (RegistryKey regKey = rootKey.OpenSubKey(key))
                    {
                        Guid clsid = COMUtilities.ReadGuidFromKey(regKey, "CLSID", null);
                        if (clsid != Guid.Empty)
                        {
                            COMProgIDEntry entry = new COMProgIDEntry(this, key, clsid, regKey);
                            progids[key] = entry;
                        }
                    }
                }
                catch (FormatException)
                {
                }
            }
            m_progids = new SortedDictionary <string, COMProgIDEntry>(progids, StringComparer.OrdinalIgnoreCase);
        }
        private void LoadFromKey(RegistryKey key)
        {
            object name = key.GetValue(null);

            if ((name != null) && (name.ToString().Length > 0))
            {
                Name = name.ToString();
            }
            else
            {
                Name = String.Format("{{{0}}}", Iid.ToString());
            }

            ProxyClsid = COMUtilities.ReadGuidFromKey(key, "ProxyStubCLSID32", null);
            NumMethods = COMUtilities.ReadIntFromKey(key, "NumMethods", null);

            if (NumMethods < 3)
            {
                NumMethods = 3;
            }

            TypeLib        = COMUtilities.ReadGuidFromKey(key, "TypeLib", null);
            TypeLibVersion = COMUtilities.ReadStringFromKey(key, "TypeLib", "Version");

            Base = COMUtilities.ReadStringFromKey(key, "BaseInterface", null);
            if (Base.Length == 0)
            {
                Base = "IUnknown";
            }
        }
示例#5
0
 private void LoadFromKey(RegistryKey key)
 {
     Clsid          = COMUtilities.ReadGuidFromKey(key, null, "CLSID");
     ActivationType = (ActivationType)COMUtilities.ReadIntFromKey(key, null, "ActivationType");
     TrustLevel     = (TrustLevel)COMUtilities.ReadIntFromKey(key, null, "TrustLevel");
     Threading      = COMUtilities.ReadIntFromKey(key, null, "Threading");
     DllPath        = COMUtilities.ReadStringFromKey(key, null, "DllPath");
     Server         = COMUtilities.ReadStringFromKey(key, null, "Server");
     Permissions    = string.Empty;
     byte[] permissions = key.GetValue("Permissions", new byte[0]) as byte[];
     Permissions = COMSecurity.GetStringSDForSD(permissions);
 }
示例#6
0
 private void LoadProgIDs(RegistryKey rootKey)
 {
     m_progids = new SortedDictionary <string, COMProgIDEntry>();
     string[] subkeys = rootKey.GetSubKeyNames();
     foreach (string key in subkeys)
     {
         try
         {
             using (RegistryKey regKey = rootKey.OpenSubKey(key))
             {
                 Guid clsid = COMUtilities.ReadGuidFromKey(regKey, "CLSID", null);
                 if (clsid != Guid.Empty)
                 {
                     COMProgIDEntry entry = new COMProgIDEntry(key, clsid, regKey);
                     m_progids.Add(key, entry);
                 }
             }
         }
         catch (FormatException)
         {
         }
     }
 }
        private void LoadFromKey(RegistryKey key)
        {
            HashSet <Guid> categories = new HashSet <Guid>();
            object         name       = key.GetValue(null);

            Name = null;
            if (name != null)
            {
                string s = name.ToString().Trim();

                if (s.Length > 0)
                {
                    Name = name.ToString();
                }
            }

            bool fake_name = false;

            if (Name == null)
            {
                fake_name = true;
                Name      = Clsid.FormatGuidDefault();
            }

            Dictionary <COMServerType, COMCLSIDServerEntry> servers = new Dictionary <COMServerType, COMCLSIDServerEntry>();
            COMCLSIDServerEntry inproc_server = ReadServerKey(servers, key, COMServerType.InProcServer32);

            ReadServerKey(servers, key, COMServerType.LocalServer32);
            ReadServerKey(servers, key, COMServerType.InProcHandler32);
            Servers = new ReadOnlyDictionary <COMServerType, COMCLSIDServerEntry>(servers);

            if (fake_name && inproc_server != null && inproc_server.HasDotNet)
            {
                Name = String.Format("{0}, {1}", inproc_server.DotNet.ClassName, inproc_server.DotNet.AssemblyName);
            }

            AppID = COMUtilities.ReadGuidFromKey(key, null, "AppID");
            if (AppID == Guid.Empty)
            {
                AppID = COMUtilities.ReadGuidFromKey(Registry.ClassesRoot,
                                                     String.Format(@"AppID\{0}", Path.GetFileName(DefaultServer)), "AppID");
            }

            if (AppID != Guid.Empty && !servers.ContainsKey(COMServerType.LocalServer32))
            {
                servers.Add(COMServerType.LocalServer32, new COMCLSIDServerEntry(COMServerType.LocalServer32, "<APPID HOSTED>"));
            }

            TypeLib = COMUtilities.ReadGuidFromKey(key, "TypeLib", null);
            if (key.HasSubkey("Control"))
            {
                categories.Add(ControlCategory);
            }

            if (key.HasSubkey("Insertable"))
            {
                categories.Add(InsertableCategory);
            }

            if (key.HasSubkey("DocObject"))
            {
                categories.Add(DocumentCategory);
            }

            using (RegistryKey catkey = key.OpenSubKey("Implemented Categories"))
            {
                if (catkey != null)
                {
                    string[] subKeys = catkey.GetSubKeyNames();
                    foreach (string s in subKeys)
                    {
                        Guid g;

                        if (Guid.TryParse(s, out g))
                        {
                            categories.Add(g);
                        }
                    }
                }
            }

            Categories = categories.ToList().AsReadOnly();
            TreatAs    = COMUtilities.ReadGuidFromKey(key, "TreatAs", null);

            using (RegistryKey elev_key = key.OpenSubKey("Elevation"),
                   vso_key = key.OpenSubKey("VirtualServerObjects"))
            {
                if (elev_key != null)
                {
                    using (var base_key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
                                                                  Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Default))
                    {
                        int auto_approval = COMUtilities.ReadIntFromKey(base_key,
                                                                        @"SOFTWARE\Microsoft\Windows NT\CurrentVersion\UAC\COMAutoApprovalList", Clsid.ToString("B"));
                        Elevation = new COMCLSIDElevationEntry(elev_key, vso_key, auto_approval != 0);
                    }
                }
            }

            ActivatableFromApp = _app_activatable.Contains(Clsid);
        }
示例#8
0
        private void LoadFromKey(RegistryKey key)
        {
            object name = key.GetValue(null);

            Name = null;
            if (name != null)
            {
                string s = name.ToString().Trim();

                if (s.Length > 0)
                {
                    Name = name.ToString();
                }
            }

            if (Name == null)
            {
                Name = Clsid.ToString("B");
            }

            RegistryKey serverKey = key.OpenSubKey("InProcServer32");

            try
            {
                ServerType = COMServerType.InProcServer32;
                if (serverKey == null)
                {
                    serverKey  = key.OpenSubKey("LocalServer32");
                    ServerType = COMServerType.LocalServer32;
                }

                if ((serverKey != null) && (serverKey.GetValue(null) != null))
                {
                    CmdLine = serverKey.GetValue(null).ToString();
                    Server  = ProcessFileName(CmdLine, ServerType == COMServerType.LocalServer32);
                    string threading_model = serverKey.GetValue("ThreadingModel") as string;
                    if (threading_model != null)
                    {
                        switch (threading_model.ToLower())
                        {
                        case "both":
                            ThreadingModel = COMThreadingModel.Both;
                            break;

                        case "free":
                            ThreadingModel = COMThreadingModel.Free;
                            break;

                        case "neutral":
                            ThreadingModel = COMThreadingModel.Neutral;
                            break;

                        case "apartment":
                        default:
                            ThreadingModel = COMThreadingModel.Apartment;
                            break;
                        }
                    }
                    else if (ServerType == COMServerType.LocalServer32)
                    {
                        ThreadingModel = COMThreadingModel.Both;
                    }

                    try
                    {
                        // Expand out any short filenames
                        if (Server.Contains("~") && !IsInvalidFileName(Server))
                        {
                            Server = Path.GetFullPath(Server);
                        }
                    }
                    catch (IOException)
                    {
                    }
                    catch (SecurityException)
                    {
                    }
                    catch (ArgumentException)
                    {
                    }
                }
                else
                {
                    Server     = String.Empty;
                    ServerType = COMServerType.UnknownServer;
                }
            }
            finally
            {
                if (serverKey != null)
                {
                    serverKey.Close();
                }
            }

            AppID = Guid.Empty;

            try
            {
                object appid = key.GetValue("AppID");
                if ((appid != null) && (appid.ToString().Length > 0))
                {
                    Guid appid_guid;
                    if (Guid.TryParse(appid.ToString(), out appid_guid))
                    {
                        if (appid_guid != Guid.Empty)
                        {
                            if (ServerType == COMServerType.UnknownServer)
                            {
                                ServerType = COMServerType.LocalServer32;
                            }
                            AppID = appid_guid;
                        }
                    }
                }
            }
            catch (FormatException e)
            {
                System.Diagnostics.Debug.WriteLine(e.ToString());
            }

            TypeLib = COMUtilities.ReadGuidFromKey(key, "TypeLib", null);
            if (key.HasSubkey("Control"))
            {
                m_categories.Add(ControlCategory);
            }

            if (key.HasSubkey("Insertable"))
            {
                m_categories.Add(InsertableCategory);
            }

            if (key.HasSubkey("DocObject"))
            {
                m_categories.Add(DocumentCategory);
            }

            using (RegistryKey categories = key.OpenSubKey("Implemented Categories"))
            {
                if (categories != null)
                {
                    string[] subKeys = categories.GetSubKeyNames();
                    foreach (string s in subKeys)
                    {
                        Guid g;

                        if (Guid.TryParse(s, out g))
                        {
                            m_categories.Add(g);
                        }
                    }
                }
            }

            TreatAs = COMUtilities.ReadGuidFromKey(key, "TreatAs", null);
        }