-2

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

Alex K.
  • 171,639
  • 30
  • 264
  • 288
Walkirio
  • 11
  • 3
  • 1
    Would registering your application as a Windows Service be possible / more appropriate (if it runs in the background). – gunr2171 Oct 11 '18 at 14:47
  • Honestly, I never tried to implement a Windows Service, is it the same to code? – Walkirio Oct 11 '18 at 14:58
  • Depends on what type of software you made. If you have something with a UI it's going to be much harder. You'll want to start with [some research](https://learn.microsoft.com/en-us/dotnet/framework/windows-services/walkthrough-creating-a-windows-service-application-in-the-component-designer). – gunr2171 Oct 11 '18 at 14:59
  • Thank you ! I'll do some research about this strategy. – Walkirio Oct 11 '18 at 15:04

1 Answers1

0

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.

Echo
  • 67
  • 3
  • I prefer to fix the problem automatically from my software. – Walkirio Oct 11 '18 at 15:12
  • Unfortunately it's very difficult to diagnose what the problem might be from what you've written above. It may not be an issue with your software, especially if it runs okay once the operating system has finished loading up. If it is a problem with your software you might have some luck investigating the Event Viewer to see if there's a specific error message you can work from. – Echo Oct 11 '18 at 15:21