unity开机自启两种方法

1,command + R,输入shell:startup,放入快捷方式

2,unity代码设置

//设置开机自启    
 try
     {
         string path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
         RegistryKey rgkRun =         Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
         if (rgkRun == null)
         {
             rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
         }
         rgkRun.SetValue("dhstest", path);
     }
     catch
     {
         Debug.Log(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
     
     }
      finally
     {
         regeditkey();
     }

//取消开机自启
try
     {
         string path = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
         RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
             true);
         if (rgkRun == null)
         {
             rgkRun = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
         }
         rgkRun.DeleteValue("dhstest", false);
     }
     catch
     {
         Debug.Log("error");
     }
     finally
     {
         regeditkey();
         Debug.Log(123);
     }

public void regeditkey()
 {
     RegistryKey rgkRun = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
     
 }

 

你可能感兴趣的:(unity)