Run C# application at Windows startup?

℡╲_俬逩灬. 提交于 2019-12-26 23:12:43

问题


It's all the day that I'm trying to implement a startup feature into my project.

I used Registry key:

//Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run (Administrator Rights)

I used Registry key:

//Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run (Administrator Rights) 

The code work but when I restart the computer nothing happens.

This is the code I used.

RegistryKey registryKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
registryKey.SetValue("ApplicationService", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "MyService.exe"));

I also used Startup folder linked with a shortcut to my .exe location(inside %appdata%). Unfortunately, it didn't work.

My operative system is: Windows 10 - PRO 1083. My project has been developed with C#.

Do you know something else?

I need you to figure out that issue ! Thanks in advance for your answers


回答1:


One nice easy way to do this is a scheduled task. There's a wizard in Windows (search in the start menu: Task Scheduler) that should guide you through the process.

You select Create Task and can set the task trigger to be computer start-up. Once that's done, it should just be a matter of selecting your executable and from then it should run.

If that doesn't work, try executing the program from a .bat file and running that at startup - it might be a little niche, but that's alleviated problems I've had before with programs on startup.



来源:https://stackoverflow.com/questions/52762945/run-c-sharp-application-at-windows-startup

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