Example #1
0
        // Set Active Setup registry keys into HKEY_LOCAL_MACHINE\SOFTWARE or HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node
        /// <summary>
        /// Set Active Setup registry keys into HKEY_LOCAL_MACHINE\SOFTWARE
        /// or HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node
        /// by providing <paramref name="ComponentID"/> followerd by <paramref name="StubPath"/>, <paramref name="Is32bitApp"/>, optionally <paramref name="Version"/> and <paramref name="Locale"/>
        /// </summary>
        /// <example>
        /// <code>
        /// ActiveSetup.Set("Google_Chrome_71", @"C:\ProgramData\Active Setup\Google_Chrome_71\ActiveSetup.cmd", false);
        /// </code>
        /// </example>
        /// <seealso cref="CMActiveSetup.Undo(string)"/>
        /// <seealso cref="CMWinRegistry.GetActiveSetupKeys()"/>
        /// <param name="ComponentID">The name of the program to Unset, wildcards ? or * are allowerd, non case sensitive</param>
        /// <param name="StubPath">The path where active setup script or batch is located</param>
        /// <param name="Is32bitApp">Specify if the application for which active setup should be create is 32 bit or 64</param>
        /// <param name="Version">Version of the Active Setup Key</param>
        /// <param name="Locale">Specify locale, if needed</param>
        public static void Set(string ComponentID, string StubPath, bool Is32bitApp, string Version = "1,0", string Locale = "*")
        {
            List <CMWinRegistry.WinRegPath> machineKeys = CMWinRegistry.GetActiveSetupKeys().Where(x => x.Scope == "Machine").ToList();

            if (Environment.Is64BitOperatingSystem && Is32bitApp)
            {
                machineKeys = machineKeys.Where(x => x.RegPath.Contains("Wow6432Node")).ToList();
            }
            else
            {
                machineKeys = machineKeys.Where(x => !x.RegPath.Contains("Wow6432Node")).ToList();
            }

            RegistryKey activeSetupKey = CMWinRegistry.RegKeyFromString(machineKeys[0].RegPath, true).CreateSubKey(ComponentID);

            activeSetupKey.SetValue(ComponentID, RegistryValueKind.String);
            activeSetupKey.SetValue(StubPath, RegistryValueKind.String);
            activeSetupKey.SetValue(Version, RegistryValueKind.String);
            activeSetupKey.SetValue(Locale, RegistryValueKind.String);
        }
Example #2
0
 // Undo all related Active Setup registry keys
 /// <summary>
 /// Undo all related <paramref name="ComponentID"/> Active Setup registry keys.
 /// </summary>
 /// <example>
 /// <code>
 /// ActiveSetup.Undo("*chrome*");
 /// </code>
 /// </example>
 /// <seealso cref="CMActiveSetup.Set(string, string, bool, string, string)"/>
 /// <seealso cref="CMWinRegistry.GetActiveSetupKeys()"/>
 /// <param name="ComponentID">The name of the program to Unset, wildcards ? or * are allowerd, non case sensitive</param>
 public static void Undo(string ComponentID)
 {
     // Delete registry keys
     foreach (CMWinRegistry.WinRegPath activeSetupKey in CMWinRegistry.GetActiveSetupKeys())
     {
         foreach (string regKey in CMWinRegistry.GetSubKeyNames(activeSetupKey.RegPath))
         {
             if (regKey.Like(ComponentID))
             {
                 try
                 {
                     CMWinRegistry.RegKeyFromString(activeSetupKey.RegPath, true).DeleteSubKey(regKey);
                 }
                 catch (Exception ex)
                 {
                     //Support.WriteLog(ex.Message.ToString());
                 }
             }
         }
     }
 }