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

553 views Asked by At

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.
2

There are 2 answers

0
Stokke On

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.

3
SteveFerg On

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");