天天看點

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

                 if (run.getvalue("校園網登陸器") == null)

                     start_with_win1.checked = true;

                     start_with_win2.checked = true;

                     string exefilename = application.executablepath;//含可執行檔案名

                     run.setvalue("校園網登陸器", exefilename);

                 else

         }

繼續閱讀