-
Overview
Most of the online search results prioritize registry settings, this method requires administrator privileges, which may not be applicable in practice. This method is written directly to the user's boot directory, and the system will boot with it. (Most search results on the web are based on registry preferences, which requires administrator privileges and may not be applicable in practice. This method is written directly to the user's boot directory, and the system boot will be started with it.)
-
Code.
/// <summary> /// Setting the program to run automatically /// </summary> /// <param name="IsAppAutoStart"> Whether or not to power on the app and start it up </param> public static bool SetAppAutoRun(bool IsAppAutoStart=true) { string sourseEXE = (, ""); string startup_ShortcutPath = () + @"\"; if (IsAppAutoStart)//need to create a bootloader { if ((startup_ShortcutPath)) { (startup_ShortcutPath); } CreateShortcut(sourseEXE, startup_ShortcutPath); } else { if ((startup_ShortcutPath)) { (startup_ShortcutPath); } } } /// <summary> /// Create a shortcut (user level) /// </summary> /// <param name="targetPath"> target program path.exe</param> /// <param name="shortcutPath"> shortcut placement path.lnk</param> private static bool CreateShortcut(string targetPath, string shortcutPath) { try {
// Reflection var shellType = ("");//This is the shortcut generation program that comes with windows, you can borrow it directly. dynamic shell = (shellType); var shortcut = (shortcutPath); = targetPath; // = "arguments appended to paths space-separated"; // = "Remarks information"; // = ; // = "icon path"; (); return true; } catch (Exception ex) { return false; } }