示例#1
0
        public static bool DisableProxyAutoConfig()
        {
            try
            {
                if (!IsProxyAutoConfigEnable())
                {
                    //RefreshProxySettings();
                    return(true);
                }

                RegistryKey registry = Registry.CurrentUser.OpenSubKey(
                    "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
                    true);
                if (registry != null)
                {
                    registry.DeleteValue("AutoConfigURL", false);
                    registry.Flush();
                    registry.Close();
                }
                RefreshProxySettings();
                if (!IsProxyAutoConfigEnable())
                {
                    return(true);
                }
            }
            catch (Exception)
            {
            }

            return(false);
        }
示例#2
0
 /// <summary>
 /// 注册应用信息
 /// </summary>
 /// <param name="setupPath">安装路径</param>
 public static void AddRegedit(string setupPath)
 {
     try
     {
         RegistryKey key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64);
         if (!Is64Bit())
         {
             key = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32);
         }
         RegistryKey software = key.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall", true).CreateSubKey(sFingerPrint);
         software.SetValue("DisplayIcon", setupPath + "\\" + AppIco);
         software.SetValue("DisplayName", ControlPanelDisplayName);
         software.SetValue("DisplayVersion", Version);
         software.SetValue("Publisher", Publisher);
         software.SetValue("InstallLocation", setupPath);
         software.SetValue("InstallSource", setupPath);
         software.SetValue("UninstallString", setupPath + "\\" + UninstallExe);
         software.SetValue("InstallGuid", InstallGuid);
         software.SetValue("InstallDateTime", InstallDateTime.ToString());
         software.Flush();
         software.Close();
         key.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
示例#3
0
 /// <summary>
 /// Forces a flush of the changes if values have been changed
 /// </summary>
 public void Flush()
 {
     if (regkey != null)
     {
         regkey.Flush();
     }
 }
示例#4
0
        public void Save()
        {
            RegistryKey key = Registry.CurrentUser.CreateSubKey(_strKey);

            if (key != null)
            {
                foreach (KeyValuePair <string, object> de in Options)
                {
                    TypeConverter tc;
                    String        s;

                    if (de.Value == null)
                    {
                        s = "";
                    }
                    else
                    {
                        if (de.Value is int[])
                        {
                            tc = new IntegerArrayConverter();
                        }
                        else
                        {
                            tc = TypeDescriptor.GetConverter(de.Value);
                        }

                        s = tc.ConvertToString(de.Value);
                    }

                    key.SetValue(de.Key, s);
                }

                key.Flush();
            }
        }
示例#5
0
        static private int DisableShutdownReasonUI()
        {
            try
            {
                RegistryKey regKey =
                    Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Policies").OpenSubKey("Microsoft")
                    .OpenSubKey("Windows NT", true).OpenSubKey("Reliability", true);
                if (regKey == null)
                {
                    if (Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Policies").OpenSubKey("Microsoft").OpenSubKey("Windows NT") == null)
                    {
                        regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Policies").OpenSubKey("Microsoft", true).CreateSubKey("Windows NT");
                        if (regKey == null)
                        {
                            throw new Exception("Couldn't create/open the registry key to change (HKLM.SOFTWARE.Policies.Microsoft.Windows NT");
                        }
                        regKey.Flush();
                        regKey.Close();
                    }
                    regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Policies").OpenSubKey("Microsoft").OpenSubKey("Windows NT", true)
                             .CreateSubKey("Reliability");
                    if (regKey == null)
                    {
                        throw new Exception("Couldn't create/open the registry key to change(HKLM.SOFTWARE.Policies.Microsoft.Windows NT.Reliability)");
                    }
                    regKey.Flush();
                    regKey.Close();
                    regKey = Registry.LocalMachine.OpenSubKey("SOFTWARE").OpenSubKey("Policies").OpenSubKey("Microsoft").OpenSubKey("Windows NT").OpenSubKey("Reliability", true);
                    if (regKey == null)
                    {
                        throw new Exception("Couldn't create/open the registry key to change(HKLM.SOFTWARE.Policies.Microsoft.Windows NT.Reliability)");
                    }
                }
                regKey.SetValue("ShutdownReasonUI", 0);
                regKey.SetValue("ShutdownReasonOn", 0);
                regKey.Flush();
                regKey.Close();

                Log("ShutdownReasonUI was turned off");
                return(0);
            }
            catch (Exception e)
            {
                Log("Could not disable shutdown reason UI");
                return(1);
            }
        }
        private void PCyeDatabaseBaglantıAdresKaydı()
        {
            RegistryKey registryKey = Registry.CurrentUser;

            registryKey = registryKey.CreateSubKey("Software\\FlapYazilimDatabaseBilgileri");
            registryKey.SetValue("Connect", $@"Persist Security Info=True;User Id={DatabaseKullaniciAdi};Password={DatabaseSifre};Initial Catalog={DatabaseAdi};Data Source={ServerAdi}");
            registryKey.Flush();
        }
示例#7
0
    private static void write_lwsn_path(string value)
    {
        RegistryKey LocalMachineKey = Microsoft.Win32.Registry.LocalMachine;
        RegistryKey lw_unity_key    = LocalMachineKey.CreateSubKey(lw_unity_key_path);

        lw_unity_key.SetValue(lw_unity_value_name, value, RegistryValueKind.String);
        lw_unity_key.Flush();
    }
示例#8
0
文件: WinReg.cs 项目: zhangrl/Hunter3
        /// <summary>
        /// 给某类型文件设置文件关联,自动添加Open关联
        /// </summary>
        /// <param name="fileExdName">扩展名</param>
        /// <param name="declaration">描述</param>
        /// <param name="filetype">文件类型</param>
        public static void SaveRelevant(string fileExdName, string filetype, string declaration)
        {
            RegistryKey rkClassesRoot = Registry.ClassesRoot.OpenSubKey("", true); //ClassesRoot节点

            RegistryKey rk = rkClassesRoot.OpenSubKey(fileExdName, RegistryKeyPermissionCheck.ReadWriteSubTree,
                                                      System.Security.AccessControl.RegistryRights.FullControl); //尝试打开文件类型的键 如.hunt"

            if (rk != null)
            {
                rkClassesRoot.DeleteSubKey(fileExdName, true);                //如果存在这个键,则删除
            }
            rkClassesRoot.Flush();

            rk = rkClassesRoot.CreateSubKey(fileExdName, RegistryKeyPermissionCheck.ReadWriteSubTree); //建立一个ClassesRoot下的键,为文件类型
            rk.SetValue("", filetype);                                                                 //增加描述 如 huntertaskFile
            rk.Flush();

            rk = rkClassesRoot.OpenSubKey(filetype, true);     //建立一个子键
            if (rk != null)
            {
                rkClassesRoot.DeleteSubKeyTree(filetype);
            }
            rkClassesRoot.Flush();

            rkClassesRoot.CreateSubKey(filetype).SetValue("", declaration);

            //获得一个可以操作子键的实例
            rk = rkClassesRoot.OpenSubKey(filetype, true);
            //以下为依次建立键值
            rk.CreateSubKey("DefaultIcon").SetValue("", Application.ExecutablePath + ",0");//建立关联图标
            rk.CreateSubKey("Shell");
            rk.Flush();
            rk = rk.OpenSubKey("Shell", true);
            rk.CreateSubKey("Open");
            rk.Flush();
            rk = rk.OpenSubKey("Open", true);
            rk.CreateSubKey("Command");
            rk.Flush();
            rk = rk.OpenSubKey("Command", true);
            string _PathString = Application.ExecutablePath + " %1";

            rk.SetValue("", _PathString);
            rk.Flush();

            rkClassesRoot.Flush();
        }
示例#9
0
 protected void OnDeleteEvent(object sender, DeleteEventArgs a)
 {
     saveConfig();
     softwareKey.Flush();
     led_matrix.requestStop();
     Application.Quit();
     a.RetVal = true;
 }
示例#10
0
 /// <summary>
 /// Renames a subkey of the passed in registry key since
 /// the Framework totally forgot to include such a handy feature.
 /// </summary>
 /// <param name="parentKey">The RegistryKey that contains the subkey
 /// you want to rename (must be writeable)</param>
 /// <param name="subKeyName">The name of the subkey that you want to rename
 /// </param>
 /// <param name="newSubKeyName">The new name of the RegistryKey</param>
 /// <returns>True if succeeds</returns>
 public static bool RenameSubKey(RegistryKey parentKey,
                                 string subKeyName, string newSubKeyName)
 {
     CopyKey(parentKey, subKeyName, newSubKeyName);
     parentKey.DeleteSubKeyTree(subKeyName);
     parentKey.Flush();
     return(true);
 }
示例#11
0
        internal static void SetValue(RegistryKeys regKey, string value)
        {
            RegistryKey mainKey = Registry.CurrentUser.CreateSubKey(MainKeyName, true);

            mainKey.SetValue(regKey.ToString(), value);
            mainKey.Flush();
            mainKey.Close();
        }
示例#12
0
 public static void StoreLicenseKey(string license)
 {
     using (RegistryKey softRegKey = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\VoteManager", true))
     {
         softRegKey.SetValue("activationkey", license, RegistryValueKind.String);
         softRegKey.Flush();
     }
 }
示例#13
0
        public static bool SetActiveProxy(IPEndPoint gateway)
        {
            try
            {
                if (gateway.Address.Equals(IPAddress.Any))
                {
                    gateway.Address = IPAddress.Loopback;
                }
                string proxyString = string.Format("{0}:{1}", gateway.Address, gateway.Port);
                proxyString = string.Format("http={0};" + "https={0};" + "socks={0};", proxyString);
                if (IsProxyEnable(proxyString))
                {
                    RefreshProxySettings();
                    return(true);
                }

                StructInternetProxyInfo proxyInfo;
                proxyInfo.DwAccessType = InternetOpenTypeProxy;
                proxyInfo.Proxy        = Marshal.StringToHGlobalAnsi(proxyString);
                proxyInfo.ProxyBypass  = Marshal.StringToHGlobalAnsi("<local>");
                IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(proxyInfo));
                Marshal.StructureToPtr(proxyInfo, intptrStruct, true);

                if (InternetSetOption(IntPtr.Zero, InternetOptionProxy, intptrStruct, Marshal.SizeOf(proxyInfo)))
                {
                    InternetSetOption(IntPtr.Zero, InternetOptionProxySettingsChanged, IntPtr.Zero, 0);
                    InternetSetOption(IntPtr.Zero, InternetOptionSettingsChanged, IntPtr.Zero, 0);
                    InternetSetOption(IntPtr.Zero, InternetOptionRefresh, IntPtr.Zero, 0);
                    Thread.Sleep(1000);
                    if (IsProxyEnable(proxyString))
                    {
                        return(true);
                    }
                }

                RegistryKey registry =
                    Registry.CurrentUser.OpenSubKey(
                        "Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings",
                        true);
                if (registry != null)
                {
                    registry.SetValue("ProxyEnable", 1);
                    registry.SetValue("ProxyServer", proxyString);
                    registry.Flush();
                    registry.Close();
                }
                RefreshProxySettings();
                if (IsProxyEnable(proxyString))
                {
                    return(true);
                }
            }
            catch (Exception)
            {
            }

            return(false);
        }
示例#14
0
        private void RemoveServer(string servername)
        {
            RegistryKey servers = Registry.CurrentUser.OpenSubKey("Software\\SafT\\RDPClient\\Servers", true);

            servers.DeleteValue(servername);
            servers.Close();
            servers.Flush();
            BuildTree();
        }
示例#15
0
 private bool regWriteString(string sValuename, string s)
 {
     if (_regKey == null)
     {
         return(false);
     }
     try
     {
         _regKey.SetValue(sValuename, s);
         _regKey.Flush();
         return(true);
     }
     catch (Exception x)
     {
         Debug.WriteLine("Exception in regWriteStrings for '" + _regSubKey + "'. " + x.Message);
         return(false);
     }
 }
示例#16
0
        private void RemoveServer()
        {
            RegistryKey servers = Registry.CurrentUser.OpenSubKey("Software\\SafT\\RDPClient\\Servers", true);

            servers.DeleteSubKey(treeView1.SelectedNode.Text, false);
            servers.Close();
            servers.Flush();
            BuildTree();
        }
示例#17
0
        private void listView_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            if (e.CancelEdit)
            {
                bool         close;
                RegistryKey  key     = GetKey(treeView.SelectedNode, true, out close);
                bool         process = true;
                ListViewItem item    = listView.Items[e.Item];

                if (key != null && e.Label != item.Name)
                {
                    try
                    {
                        try
                        {
                            if (key.GetValueKind(e.Label) != RegistryValueKind.Unknown)
                            {
                                process =
                                    (MessageBox.Show(
                                         string.Format(SharedStrings.RegistryView_ReplaceConfirm, e.Label),
                                         DialogTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                         MessageBoxDefaultButton.Button2) == DialogResult.Yes);
                                if (process)
                                {
                                    key.DeleteValue(e.Label);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            Trace.Write(ex.Message);
                        }

                        // set new value:
                        if (process)
                        {
                            key.SetValue(e.Label, key.GetValue(item.Name), key.GetValueKind(item.Name));
                            key.DeleteValue(item.Name);
                            key.Flush();

                            PopulateListView(key);
                        }
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(SharedStrings.RegistryView_UnableToChangeName + Environment.NewLine + ex.Message,
                                        DialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }

                e.CancelEdit = true;
                if (close && key != null)
                {
                    key.Close();
                }
            }
        }
示例#18
0
 /// <summary>
 /// Сохранить настройки и освободить ресурсы.
 /// </summary>
 public void Dispose()
 {
     if (_key != null)
     {
         _key.Flush();
         _key.Close();
         _key = null;
     }
 }
示例#19
0
        private void CheckExpiryDate()
        {
            // Attempt to open the key
            RegistryKey key = Registry.LocalMachine.OpenSubKey
                                  (@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\LastRun");

            // If the return value is null, the key doesn't exist
            if (key == null)
            {
                // The key doesn't exist; create it / open it
                key = Registry.LocalMachine.CreateSubKey
                          (@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\LastRun");

                key.SetValue("Date",
                             DateTime.Today.ToShortDateString(),
                             RegistryValueKind.String);

                key.Flush();
                key.Close();
            }

            // Attempt to retrieve the value X; if null is returned, the value
            // doesn't exist in the registry.
            if (key.GetValue("Date") != null)
            {
                // The value exists; move the form to the coordinates stored in the
                // registry.
                DateTime dt;
                DateTime.TryParse(key.GetValue("Date").ToString(), out dt);

                if (numberOfValidDays == -1)
                {
                    // run on odd days
                    TimeSpan ts = dt.Subtract(DateTime.Now);

                    int days = ts.Days;

                    if (days < 0)
                    {
                        days = -days; // make positive
                    }
                    if ((days % 2) == 1)
                    {
                        Application.Exit();
                    }
                }
                else
                {
                    // date in registry + 2 days is greater than today.. dont run..
                    if (dt.AddDays(numberOfValidDays).CompareTo(DateTime.Now) < 0)
                    {
                        Application.Exit();
                    }
                }
            }
        }
示例#20
0
        void some_Click(object sender, EventArgs e)
        {
            ToolStripMenuItem c            = (ToolStripMenuItem)sender;
            RegistryKey       servertomove = Registry.CurrentUser.OpenSubKey(Common_functions.Settings.common_reg_string + "\\Servers\\" + treeView1.SelectedNode.Text, true);

            servertomove.SetValue("Folder", c.Text);
            servertomove.Close();
            servertomove.Flush();
            BuildTree();
        }
示例#21
0
        public static void ClearAllSettings()
        {
            RegistryKey myKey = Application.UserAppDataRegistry;

            foreach (var key in myKey.GetValueNames())
            {
                myKey.DeleteValue(key);
            }
            myKey.Flush();
        }
 public void SetUp()
 {
     key = Registry.CurrentUser.CreateSubKey("RegistryVariableSourceTests");
     key.SetValue("name", "Aleks Seovic");
     key.SetValue("computer_name", "%COMPUTERNAME% is the name of my computer", RegistryValueKind.ExpandString);
     key.SetValue("age", 32, RegistryValueKind.DWord);
     key.SetValue("family", new string[] { "Marija", "Ana", "Nadja" });
     key.SetValue("bday", new byte[] { 24, 8, 74 });
     key.Flush();
 }
示例#23
0
        internal void CopyKey(RegistryKey parentKey, string keyNameToCopy, string newKeyName)
        {
            RegistryKey destinationKey = parentKey.CreateSubKey(newKeyName);

            RegistryKey sourceKey = parentKey.OpenSubKey(keyNameToCopy);

            RecurseCopyKey(sourceKey, destinationKey);
            sourceKey.Flush();
            sourceKey.Close();
        }
示例#24
0
        //设置初始化状态
        public void SetIniState(int state)
        {
            RegistryKey rk   = Registry.LocalMachine;
            RegistryKey conv = rk.CreateSubKey(@"SOFTWARE\ExcelConvert");

            rk.Close();
            conv.SetValue("IniState", state, RegistryValueKind.DWord);
            conv.Flush();
            conv.Close();
        }
示例#25
0
        public static void AddToContextMenuNew()
        {
            RegistryKey rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\.ctxt\ShellNew");

            rk.SetValue("Filename", "");
            rk = Registry.LocalMachine.CreateSubKey(@"SOFTWARE\Classes\.ctxt\PersistentHandler");
            rk.SetValue("", "{5e941d80-bf96-11cd-b579-08002b30bfeb}");
            rk.Flush();
            rk.Close();
        }
示例#26
0
        public static void EnableSideloadingApps()
        {
            RegistryKey rk     = Registry.LocalMachine.OpenSubKey(@"Software\Policies\Microsoft\Windows", true);
            RegistryKey subkey = rk.OpenSubKey("AppX", true) ?? rk.CreateSubKey("AppX");

            subkey.SetValue("AllowAllTrustedApps", 1, RegistryValueKind.DWord);
            subkey.Flush();
            subkey.Dispose();
            Log.Comment("Sideloading is enabled");
        }
        private void cbUnlockHiddenScroll_MouseClick(object sender, MouseEventArgs e)
        {
            try // set UIStyle
            {
                using (RegistryKey synTPCplKey = Registry.LocalMachine.OpenSubKey("Software\\Synaptics\\SynTPCpl", true))
                {
                    if (synTPCplKey != null)
                    {
                        int uiStyle = Convert.ToInt32(synTPCplKey.GetValue("UIStyle"));
                        if (uiStyle == 14)
                        {
                            synTPCplKey.SetValue("UIStyle", "15");
                            synTPCplKey.Flush();
                            uiStyle = Convert.ToInt32(synTPCplKey.GetValue("UIStyle"));
                            if (uiStyle != 15)
                            {
                                MessageBox.Show(@"Changes are not applied for some reason..", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            cbUnlockHiddenScroll.Checked = true;
                        }
                        else
                        {
                            synTPCplKey.SetValue("UIStyle", "14");
                            synTPCplKey.Flush();
                            uiStyle = Convert.ToInt32(synTPCplKey.GetValue("UIStyle"));
                            if (uiStyle != 14)
                            {
                                MessageBox.Show(@"Changes are not applied for some reason..", @"Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                            cbUnlockHiddenScroll.Checked = false;
                        }
                    }

                    synTPCplKey.Close();
                }

                restartTrayAction();
            }
            catch (Exception ex)
            {
                MessageBox.Show(@"Insufficient permissions, try running as administrator!\n\nError:" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
示例#28
0
 private void удалитьToolStripMenuItem1_Click(object sender, EventArgs e)
 {
     if (MessageBox.Show("Действительно хотите удалить сервер из списка?", "Вы уверены?") == DialogResult.Yes)
     {
         RegistryKey servertoremove = Registry.CurrentUser.OpenSubKey(Common_functions.Settings.common_reg_string + "\\Servers", true);
         servertoremove.DeleteSubKey(treeView1.SelectedNode.Text);
         servertoremove.Close();
         servertoremove.Flush();
     }
 }
        public static bool GetBool(string p_Name, bool p_DefaultValue)
        {
            string      methSig     = $"GetBool({p_Name},{p_DefaultValue})";
            RegistryKey currentUser = Registry.CurrentUser;

            TraceLogger.Debug($"{methSig}: RegistryKey[CurrentUser]='{currentUser?.Name??"NULL"}'");
            currentUser.CreateSubKey("Software\\ASCOM\\Utilities");
            RegistryKey registryKey = currentUser.OpenSubKey("Software\\ASCOM\\Utilities", true);

            TraceLogger.Debug($"{methSig}: RegistryKey[Utilities]='{registryKey?.Name ?? "NULL"}'");
            bool flag = false;

            try
            {
                if (registryKey.GetValueKind(p_Name) == RegistryValueKind.String)
                {
                    string keyValue = registryKey.GetValue(p_Name).ToString();
                    TraceLogger.Debug($"{methSig}: RegistryKey[Utilities.{p_Name}]='{keyValue ?? "NULL"}'");
                    flag = Conversions.ToBoolean(keyValue);
                }
            }
            catch (IOException ex1)
            {
                TraceLogger.Debug($"Exception1: Get RegistryValue: {ex1.GetType().Name}");
                TraceLogger.Debug(ex1.ToString());
                //ProjectData.SetProjectError((Exception) ex1);
                try
                {
                    RegistryCommonCode.SetName(p_Name, p_DefaultValue.ToString());
                    flag = p_DefaultValue;
                }
                catch (Exception ex2)
                {
                    TraceLogger.Debug($"Exception2: SetName: {ex2.GetType().Name}");
                    TraceLogger.Debug(ex2.ToString());
                    //ProjectData.SetProjectError(ex2);
                    flag = p_DefaultValue;
                    //ProjectData.ClearProjectError();
                }
                //ProjectData.ClearProjectError();
            }
            catch (Exception ex)
            {
                TraceLogger.Debug($"Exception: Get RegistryValue: {ex.GetType().Name}");
                TraceLogger.Debug(ex.ToString());
                //ProjectData.SetProjectError(ex);
                flag = p_DefaultValue;
                //ProjectData.ClearProjectError();
            }
            registryKey.Flush();
            registryKey.Close();
            currentUser.Flush();
            currentUser.Close();
            return(flag);
        }
        /// <summary>
        /// Create or overwrite a current file association for this FileAssociator's set extension.
        /// </summary>
        /// <param name="progID">The basic application name that uses this file extension.</param>
        /// <param name="description">The desription of this file extension and/or program that uses it.</param>
        /// <param name="defaultIcon">The icon to show on the program and it's files.</param>
        /// <param name="execApp">The application that will be run when the file extension is clicked.</param>
        /// <param name="openWith">The programs that appear in the OpenWith list.</param>
        /// <exception cref="Exception">Thrown when an error occurs that will prevent it from working correctly.</exception>
        public void Create(string progID, string description, ProgramIcon defaultIcon, ExecApplication execApp, OpenWithList openWith)
        {
            if (progID != null)
            {
                if (defaultIcon.IsValid && execApp.IsValid)
                {
                    Registry.CurrentUser.CreateSubKey(Extension).SetValue("", progID);
                    RegistryKey key = Registry.CurrentUser.CreateSubKey(progID,
                                                                        RegistryKeyPermissionCheck.ReadWriteSubTree);

                    if (description != null)
                    {
                        key.SetValue("", description, RegistryValueKind.String);
                    }

                    if (defaultIcon != null && defaultIcon.IsValid)
                    {
                        key.CreateSubKey("DefaultIcon").SetValue("", defaultIcon.IconPath, RegistryValueKind.String);
                    }
                    else
                    {
                        throw new Exception("The default icon you entered is either null or doesn't exist...");
                    }

                    if (execApp != null && execApp.IsValid)
                    {
                        key.CreateSubKey(@"Shell\Open\Command").SetValue("", execApp.Path + " %1", RegistryValueKind.String);
                    }
                    else
                    {
                        throw new Exception("The executable application you entered is either null or not an .exe format...");
                    }

                    if (openWith != null)
                    {
                        key = key.CreateSubKey("OpenWithList", RegistryKeyPermissionCheck.ReadWriteSubTree);
                        foreach (string file in openWith.List)
                        {
                            key.CreateSubKey(file);
                        }
                    }

                    key.Flush();
                    key.Close();
                }
                else
                {
                    throw new Exception("Either the icon or executable application object is invalid...");
                }
            }
            else
            {
                throw new Exception("The program ID you entered is null...");
            }
        }