閱讀503 返回首頁    go 阿裏雲 go 技術社區[雲棲]


C# 開機隨係統啟動

//添加啟動項


/// <summary>
         /// 開機隨係統啟動
         /// </summary>
         public void start_with_windows()
         {
             if (start_with_win1.Checked)
             {
                 start_with_win1.Checked = false;
                 start_with_win2.Checked = false;


                 RegistryKey hklm = Registry.LocalMachine;
                 RegistryKey run = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);


                 if (run.GetValue("校園網登陸器")!= null)
                 {
                     run.DeleteValue("校園網登陸器");
                 }
                 run.Close();
                 hklm.Close();
                
             }
             else
             {
                 RegistryKey hklm = Registry.LocalMachine;
                 RegistryKey run = hklm.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);


                 if (run.GetValue("校園網登陸器") == null)
                 {
                     start_with_win1.Checked = true;
                     start_with_win2.Checked = true;
                     string exeFileName = Application.ExecutablePath;//含可執行文件名
                     run.SetValue("校園網登陸器", exeFileName);
                 }
                 else
                 {
                     run.DeleteValue("校園網登陸器");
                     start_with_win1.Checked = true;
                     start_with_win2.Checked = true;
                     string exeFileName = Application.ExecutablePath;//含可執行文件名
                     run.SetValue("校園網登陸器", exeFileName);
                 }
                 run.Close();
                 hklm.Close();
             }
         }

最後更新:2017-04-02 17:51:23

  上一篇:go Android 實現縮小圖片像素
  下一篇:go 使用程序創建Android桌麵快捷方式