public static void Unregister(Guid clsid, string tlbPath)
        {
            Trace.WriteLine($"Unregistering server:");
            Trace.Indent();
            Trace.WriteLine($"CLSID: {clsid:B}");
            Trace.Unindent();

            // Unregister local server
            string serverKey = string.Format(KeyFormat.LocalServer32, clsid);

            Registry.LocalMachine.DeleteSubKey(serverKey, throwOnMissingSubKey: false);

            // Unregister type library
            TypeLib.Unregister(tlbPath);
        }
        public static void Register(Guid clsid, string exePath, string tlbPath)
        {
            // Register local server
            Trace.WriteLine($"Registering server:");
            Trace.Indent();
            Trace.WriteLine($"CLSID: {clsid:B}");
            Trace.WriteLine($"Executable: {exePath}");
            Trace.Unindent();

            string serverKey = string.Format(KeyFormat.LocalServer32, clsid);

            using RegistryKey regKey = Registry.LocalMachine.CreateSubKey(serverKey);
            regKey.SetValue(null, exePath);

            // Register type library
            TypeLib.Register(tlbPath);
        }
Exemple #3
0
        /// <summary>
        /// Unregistering server
        /// </summary>
        /// <param name="clsid"></param>
        /// <param name="progId"></param>
        /// <param name="tlbPath"></param>
        /// <param name="perUser"></param>
        static void Unregister(Guid clsid, ProgIdAttribute progId, string tlbPath, bool perUser)
        {
            Trace.WriteLine("[Enter]LocalServer.Unregister");
            Trace.Indent();
            try
            {
                Trace.WriteLine($"CLSID: {clsid:B}");
                Trace.WriteLine($"progId    : {progId?.Value}");
                Trace.WriteLine($"tlbPath   : {tlbPath}");
                Trace.WriteLine($"perUser   : {perUser}");
            }
            finally
            {
                Trace.Unindent();
            }

            RegistryKey dst;

            if (perUser)
            {
                dst = Registry.CurrentUser;
            }
            else
            {
                dst = Registry.LocalMachine;
            }
            // Unregister local server
            {
                string serverKey = string.Format(KeyFormat.formatCLSID, clsid);
                dst.DeleteSubKeyTree(serverKey, throwOnMissingSubKey: false);
            }

            if (progId != null)
            {
                //Unregister ProgId
                var progIdKey = string.Format(KeyFormat.formatProgId, progId.Value);
                dst.DeleteSubKeyTree(progIdKey, throwOnMissingSubKey: false);
            }
            if ((tlbPath != null) && (tlbPath != ""))
            {
                TypeLib.Unregister(tlbPath, perUser);
            }
            Trace.WriteLine("[Leave]LocalServer.Unregister");
        }
        public static void Register(Guid clsid, string tlbPath)
        {
            Trace.WriteLine($"Registering server with system-supplied DLL surrogate:");
            Trace.Indent();
            Trace.WriteLine($"CLSID: {clsid:B}");
            Trace.Unindent();

            string serverKey = string.Format(KeyFormat.CLSID, clsid);

            // Register App ID - use the CLSID as the App ID
            using RegistryKey regKey = Registry.LocalMachine.CreateSubKey(serverKey);
            regKey.SetValue("AppID", clsid.ToString("B"));

            // Register DLL surrogate - empty string for system-supplied surrogate
            string appIdKey = string.Format(KeyFormat.AppID, clsid);

            using RegistryKey appIdRegKey = Registry.LocalMachine.CreateSubKey(appIdKey);
            appIdRegKey.SetValue("DllSurrogate", string.Empty);

            // Register type library
            TypeLib.Register(tlbPath);
        }
        public static void Unregister(Guid clsid, string tlbPath)
        {
            Trace.WriteLine($"Unregistering server:");
            Trace.Indent();
            Trace.WriteLine($"CLSID: {clsid:B}");
            Trace.Unindent();

            // Remove the App ID value
            string serverKey = string.Format(KeyFormat.CLSID, clsid);

            using RegistryKey regKey = Registry.LocalMachine.OpenSubKey(serverKey, writable: true);
            if (regKey != null)
            {
                regKey.DeleteValue("AppID");
            }

            // Remove the App ID key
            string appIdKey = string.Format(KeyFormat.AppID, clsid);

            Registry.LocalMachine.DeleteSubKey(appIdKey, throwOnMissingSubKey: false);

            // Unregister type library
            TypeLib.Unregister(tlbPath);
        }
Exemple #6
0
        /// <summary>
        /// Registering server
        /// </summary>
        /// <param name="clsid"></param>
        /// <param name="progId"></param>
        /// <param name="exePath"></param>
        /// <param name="tlbPath"></param>
        /// <param name="perUser"></param>
        static bool Register(Guid clsid, ProgIdAttribute progId, string exePath, string tlbPath, bool perUser)
        {
            // Register local server
            Trace.WriteLine("[Enter]LocalServer.Register");
            Trace.Indent();
            try
            {
                Trace.WriteLine($"CLSID     : {clsid:B}");
                Trace.WriteLine($"progId    : {progId?.Value}");
                Trace.WriteLine($"Executable: {exePath}");
                Trace.WriteLine($"tlbPath   : {tlbPath}");
                Trace.WriteLine($"perUser   : {perUser}");
            }
            finally
            {
                Trace.Unindent();
            }

            RegistryKey dst;

            if (perUser)
            {
                dst = Registry.CurrentUser;
            }
            else
            {
                dst = Registry.LocalMachine;
            }
            Trace.WriteLine(string.Format("Target registory={0}", dst.Name));

            //create "SOFTWARE\Classes\CLSID" if not exists.
            using (var keyClasses = dst.OpenSubKey(KeyFormat.Classes, true))
            {
                const string keyCLSIDName   = "CLSID";
                string       absClassesPath = keyClasses.Name + @"\" + keyCLSIDName;

                if (keyClasses.GetSubKeyNames().Contains(keyCLSIDName))
                {
                    Trace.WriteLine(absClassesPath + " is exists.");
                }
                else
                {
                    Trace.WriteLine(absClassesPath + " is not exists.");
                    using (var keyCLSID = keyClasses.CreateSubKey(keyCLSIDName))
                    {
                        if (keyCLSID == null)
                        {
                            Trace.WriteLine(absClassesPath + " was not created.");
                            return(false);
                        }
                        else
                        {
                            Trace.WriteLine(absClassesPath + " was created.");
                        }
                    }
                }
            }

            {
                string serverKey = string.Format(KeyFormat.formatLocalServer32, clsid);
                using (var regKey = dst.CreateSubKey(serverKey))
                {
                    regKey.SetValue(null, exePath);
                    Trace.WriteLine(string.Format("[Write]\"{0}\" ← \"{1}\"", serverKey, exePath));
                }
            }

            if (progId != null)
            {//Register ProgId
                var progIdKeyName = string.Format(KeyFormat.formatProgIdCLSID, progId.Value);
                using (var keyProgId = dst.CreateSubKey(progIdKeyName))
                {
                    var clsidValue = string.Format("{{{0}}}", clsid);
                    keyProgId.SetValue(null, clsidValue);
                    Trace.WriteLine(string.Format("[Write]{0} ← {1}", keyProgId.Name, clsidValue));
                }
            }
            if ((tlbPath != null) && (tlbPath != ""))
            {
                TypeLib.Register(tlbPath, perUser);
            }
            Trace.WriteLine("[Leave]LocalServer.Register");
            return(true);
        }