0
votes

I have this simple piece of code, adding my application to run when windows start. Works fine.

RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
rk.SetValue("my_app", Application.ExecutablePath);

Then I package it with a Windows Application Packaging Project, connect it to windows store, choose "Create App Packages.." and get the resulting .appxbundle. Fine so far. I install it locally. (also installing the generated certificate (.cer) so I can install it at all.)

Once I start the installed app and click a button running the code above, nothing changes in the registry! It does not crash, I have a try..catch around the code. It just silently ignore it.

Running it from visual studio works fine, the registry gets updated.

Actually, all I want is the app to start when windows start, I am not particularly interested in how to achieve that, so any ideas are welcome!


Edit: I forgot to say the most important stuff: It is a Windows Desktop, Windows Forms App. It is not a UWP app, but a window inheriting an ordinary System.Windows.Forms.Form, compiled with x86.

Xavier mentions the StartupTask extension, it's a nuget package but it seems to be used when you have a UWP app.

1
I am trying to follow the example at docs.microsoft.com/sv-se/uwp/api/…, but I don't even know in which file to put the <Applications> part...Snorvarg

1 Answers

3
votes

Actually, all I want is the app to start when windows start, I am not particularly interested in how to achieve that, so any ideas are welcome!

You need to use the windows.startupTask Extension for your packaged UWP app. Please see Start an executable file when users log into Windows. With this extension, you can start your app whenever a user logs on.

Please note: The user has to start your application at least one time to register this startup task.