app.manifest
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
/// <summary> /// Add and delete the boot key value in the registry /// </summary> public static int SetAutoBootStatu( bool isAutoBoot) { try { 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 operation] Add registry key value: path = {0}, key = {1}, value = {2} success " , rk2.Name, " TuniuAutoboot " , execPath) ); } else { rk2.DeleteValue("MyExec", false); Console.WriteLine( string .Format( " [Registry operation] Delete registry key value: path = {0}, key = {1} successful " , rk2.Name, " TuniuAutoboot " )); } rk2.Close(); rk.Close(); return 0; } catch (Exception ex) { Console.WriteLine( string .Format( " [Registry operation] Failed to write startup information to the registry, Exception: {0} " , ex.Message)); return - 1 ; } }