private void Form1_Load (object sender, EventArgs e) { Setautobootstatu (true); }
<summary>///Add, remove power-on-boot key values in the registry///</summary> public static int Setautobootsta Tu (bool isautoboot) {try {//registrykey rk = registry.localmachine; RegistryKey RK2 = rk. CreateSubKey ("Software\\microsoft\\windows\\currentversion\\run"); Rk2. SetValue ("Myexec", Execpath); string execpath = Application.executablepath; RegistryKey rk = registry.localmachine; RegistryKey RK2 = rk. CreateSubKey ("Software\\microsoft\\windows\\currentversion\\run"); if (isautoboot) {Rk2. SetValue ("Myexec", Execpath); Console.WriteLine (String. Format ("[Registry Action] Add registry key value: Path = {0}, key = {1}, value = {2} succeeded", Rk2. Name, "Tuniuautoboot", Execpath)); } else {Rk2. DeleteValue ("Myexec", false); Console.writelinE (String. Format ("[Registry Action] Delete registry key value: Path = {0}, key = {1} succeeded", Rk2. Name, "Tuniuautoboot")); } rk2. Close (); Rk. Close (); return 0; } catch (Exception ex) {Console.WriteLine (string. Format ("[Registry Action] writes boot information to the registry failed, Exception: {0}", ex. Message)); return-1; } }
WindowsFormsApp1 Setting up boot from