示例#1
0
        /// <summary>
        /// Pins shortcut to the taskbar
        /// </summary>
        /// <example>
        /// <code>
        /// Shortcut shortcut = new Shortcut("path to shortcut");
        /// shortcut.PinToStart();
        /// </code>
        /// </example>
        /// <seealso cref="DoVerb"/>
        /// <param name="shortcut"></param>
        public static void PinToTaskBar(this Shortcut shortcut)
        {
            if (currentVersion == "6.1")
            {
                DoVerb(shortcut.Item, "Pin to Tas&kbar");
            }

            if (currentVersion == "6.3")
            {
                string keyPath1  = "shell";
                string keyPath2  = "{:}";
                string valueName = "ExplorerCommandHandler";
                string valueData = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\CommandStore\shell\Windows.taskbarpin", "ExplorerCommandHandler", "").ToString();

                RegistryKey key2 = CMWinRegistry.RegKeyFromString(@"HKLM_CURRENT_USER\SOFTWARE\Classes\*", true);
                RegistryKey key3 = key2.CreateSubKey("shell");
                RegistryKey key4 = key3.CreateSubKey("{:}");
                key4.SetValue(valueName, valueData);

                shortcut.Item.InvokeVerb("{:}");

                key3.DeleteSubKey(keyPath2);
                if (key3.SubKeyCount == 0 && key3.ValueCount == 0)
                {
                    key2.DeleteSubKey(keyPath1);
                }
            }
        }
示例#2
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);
        }
示例#3
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());
                 }
             }
         }
     }
 }
示例#4
0
        // Public method which returns all Active Setup registry paths into HKLM and from HKCU for each user (depends from thread access rights)
        /// <summary>
        /// <para>Allow to get ActiveSetup registry paths</para>
        /// </summary>
        /// <returns>Returns List of custom class ActiveSetupKey</returns>
        /// <example>
        /// <code>
        /// GetActiveSetupKeys();
        /// </code>
        /// </example>
        /// <seealso cref="CMActiveSetup.Set(string, string, bool, string, string)"/>
        /// <seealso cref="CMActiveSetup.Undo(string)"/>
        public static List <WinRegPath> GetActiveSetupKeys()
        {
            List <WinRegPath> activeSetupKeys = new List <WinRegPath>();

            activeSetupKeys.Add(new WinRegPath()
            {
                Scope = "Machine", RegPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Active Setup\Installed Components"
            });
            if (Environment.Is64BitOperatingSystem)
            {
                activeSetupKeys.Add(new WinRegPath()
                {
                    Scope = "Machine", RegPath = @"HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Active Setup\Installed Components"
                });
            }

            //Users Level Uninstall Keys
            foreach (CMWinRegistry.RegUser regUser in CMWinRegistry.GetUsersFromHiveList())
            {
                try
                {
                    if (CMWinRegistry.RegKeyFromString(@"HKEY_USERS\" + regUser.SID + @"\Software\Microsoft\Active Setup\Installed Components") != null)
                    {
                        activeSetupKeys.Add(new WinRegPath()
                        {
                            Scope = regUser.Name, RegPath = @"HKEY_USERS\" + regUser.SID + @"\Software\Microsoft\Active Setup\Installed Components"
                        });
                    }
                }
                catch (Exception ex)
                {
                    //Support.WriteLog(ex.Message.ToString());
                }
            }

            return(activeSetupKeys);
        }
示例#5
0
        //
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static DataTable Get()
        {
            List <InstalledItem> installedItems = new List <InstalledItem>();

            foreach (CMWinRegistry.WinRegPath uninstallPath in CMWinRegistry.GetUninstallKeys())
            {
                foreach (string appKeyName in CMWinRegistry.RegKeyFromString(uninstallPath.RegPath).GetSubKeyNames())
                {
                    InstalledItem installedItem = new InstalledItem()
                    {
                        Scope = uninstallPath.Scope, RegValues = CMWinRegistry.GetRegValues(CMWinRegistry.RegKeyFromString(uninstallPath.RegPath + "\\" + appKeyName))
                    };
                    installedItems.Add(installedItem);
                }
            }

            List <string> columnNames = new List <string>();

            foreach (InstalledItem installedItem in installedItems)
            {
                foreach (CMWinRegistry.RegValue regValue in installedItem.RegValues)
                {
                    if (regValue.Name != "")
                    {
                        columnNames.Add(regValue.Name);
                    }
                    else
                    {
                        columnNames.Add("WindowsKB");
                    }
                }
            }

            columnNames = columnNames.Distinct().ToList();

            DataTable result = new DataTable("InstalledPrograms");

            result.Columns.Add("Scope", typeof(String));
            foreach (string columnName in columnNames)
            {
                result.Columns.Add(columnName, typeof(String));
            }

            foreach (InstalledItem installedItem in installedItems)
            {
                DataRow row = result.NewRow();
                row["Scope"] = installedItem.Scope;
                foreach (CMWinRegistry.RegValue regValue in installedItem.RegValues)
                {
                    if (regValue.Name != "")
                    {
                        row[regValue.Name] = regValue.Data;
                    }
                    else
                    {
                        row["WindowsKB"] = regValue.Data;
                    }
                }
                result.Rows.Add(row);
            }

            return(result);
        }