Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
280 views
in Technique[技术] by (71.8m points)

registry - Run C# application at Windows startup?

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

I used Registry key:

//ComputerHKEY_LOCAL_MACHINESOFTWAREWOW6432NodeMicrosoftWindowsCurrentVersionRun (Administrator Rights)

I used Registry key:

//ComputerHKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRun (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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...