Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I run an app automatic after restart?

Tags:

c#

regedit

how can I run an app automatic after restart? (by c# code) I create A new string in 'runOnce' key in registry with the path of the App. the OS run this APP before it load the OS my problem is: My APP loads but explorer doesn't load, after I close my APP, explorer loads I restart the computer in APP, and after restart I want that my APP reopen

like image 890
sari k Avatar asked Sep 20 '11 09:09

sari k


People also ask

How do I reopen an app after restarting Windows 10?

In Sign-in options, scroll down the page until you see the “Restart apps” option. Flip the switch just below it until it's set to “On.” After that, close Settings. The next time you reboot or log out and log back in, what Microsoft calls your “restartable apps” will be reloaded automatically.


1 Answers

When you click restart from your app, make the following modifications to the registry:

Create an entry in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run registry branch.

Use

Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\YourAppName");

to create an entry.

And

RegistryKey myKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\YourAppName", true);

myKey.SetValue("YourAppName", "AppExecutablePath", RegistryValueKind.String);

to set the run path.

After the system has restarted, your app starts and removes the restart entry by calling this:

Registry.LocalMachine.DeleteSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run\\YourAppName");
like image 110
Maxim V. Pavlov Avatar answered Sep 22 '22 03:09

Maxim V. Pavlov