Ways to autorun my C# app during startup in Windows 8

会有一股神秘感。 提交于 2019-12-12 02:58:30

问题


I currently have problem in making my app autorun during startup in windows 8. I have tried to put the app in the registry. In fact I have tried both Local Machine and Current User approach:

        RegistryKey rkHKLM = Registry.LocalMachine;
        RegistryKey rkRun;
        RegistryKey rkHKCU = Registry.CurrentUser;
        RegistryKey rkRun1;

        rkRun = rkHKLM.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        rkRun1 = rkHKCU.OpenSubKey("Software\\Microsoft\\Windows\\CurrentVersion\\Run", true);
        if (checkBox1.Checked)
        {
            rkRun.SetValue("MyApp", Application.ExecutablePath);
            rkRun1.SetValue("MyApp", Application.ExecutablePath);
        }
        else
        {
            rkRun.DeleteValue("MyApp");
            rkRun1.DeleteValue("MyApp");
        }

This method does not work in Windows 8. But I don't have this problem in windows 7 or XP. Anything different for Windows 8? Is it there is any new approach?

  • For your info, I have set the app to run as admin but still doesn't autorun on startup.

回答1:


Add a link or batch file file to:

c:\Users\ (username) \AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

you could probably replace c:\Users\ (username) \AppData\Roaming with "%AppData%" in your code by

Environment.GetEnvironmentVariable("AppData");



回答2:


Putting a shortcut in: c:\Users\{login name}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup should run the application when you log in.

Optionally, you could create task. You can in the trigger choose whether it should run on log-in or when the computer starts.

The "Task Scheduler Managed Wrapper" is a helpful library for creating tasks programmatically.



来源:https://stackoverflow.com/questions/30993762/ways-to-autorun-my-c-sharp-app-during-startup-in-windows-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!