Ejemplo n.º 1
0
 /// <summary>
 /// 读取或创建注册表
 /// </summary>
 private void RegConfig()
 {
     if (Regedit.IsRegeditItemExist())
     {
         if (Regedit.IsRegeditKeyExit())
         {
             RegistryKey Key   = Registry.LocalMachine;
             RegistryKey myreg = Key.OpenSubKey("software\\DKProCloudMusic");
             var         value = myreg.GetValue("DKSet").ToString();
             myreg.Close();
             dKSet = JsonConvert.DeserializeObject <DKSet>(value);
             if (dKSet != null)
             {
                 btnAutoStart.Checked = dKSet.AutoStart;
                 btnAutoMini.Checked  = dKSet.StartWithMini;
                 rbtnHosts.Checked    = dKSet.Mode == 2;
                 if (dKSet.AutoExecute)
                 {
                     BtnStart_Click(null, null);
                 }
                 if (dKSet.StartWithMini)
                 {
                     this.WindowState = FormWindowState.Minimized;
                 }
             }
         }
     }
     else
     {
         RegistryKey key = Registry.LocalMachine;
         key.CreateSubKey("software\\DKProCloudMusic");
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// 设置自启
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnAutoStart_Click(object sender, EventArgs e)
        {
            btnAutoStart.Checked = !btnAutoStart.Checked;
            if (btnAutoStart.Checked)
            {
                dKSet.AutoStart     = true;                                                  //自动启用
                dKSet.StartWithMini = btnAutoMini.Checked;                                   //最小化
                dKSet.Mode          = btnAutoVpn.Checked ? 1 : btnAutoHosts.Checked ? 2 : 0; //启动模式
                dKSet.AutoExecute   = dKSet.Mode > 0;                                        //自动执行
                Regedit.AutoRunAfterStart();
            }
            else
            {
                dKSet.AutoStart = false;
                Regedit.DeleteSubKey();
            }
            RegistryKey key      = Registry.LocalMachine;
            RegistryKey software = key.OpenSubKey("software\\DKProCloudMusic", true);

            software.SetValue("DKSet", JsonConvert.SerializeObject(dKSet));
        }