How to get the application to be locked / unlocked at Windows startup?

1

I want to make an application that will have an option to call Regedit and the user will be able to choose whether to block or unblock for the application to start with Windows.

I've already looked at a number of websites and even here on StackOverFlow but I did not find a question that really answered my question completely, since they all had codes to do only on the user's machine manually, but I want the user to be able to choose from within an option whether to enable or not to launch the application together or be blocked when Windows starts.

I'm doing this application in C #, and would like to know how to create it. If anyone can help me, I'll be grateful.

    
asked by anonymous 27.04.2016 / 06:00

1 answer

9

Keep in mind that everything in C # is based on classes, so at first glance you should imagine that there is a class for this.

The RegistryKey (Microsoft.Win32) class is just for creating a registry key as you wish:

//Criando uma subchave nos registros, a string é o diretório padrão:
RegistryKey SeuApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);

Now the user can use two methods to create or delete the registry value, it is up to you to implement:

//Adiciona o valor no registro para iniciação com sistema.
SeuApp.SetValue("NomeApresentacao", Application.ExecutablePath);
//Remove o valor do registro.
SeuApp.DeleteValue("NomeApresentacao");

This NomeApresentacao must be renamed with the name you want to appear.

Reference: link

    
27.04.2016 / 07:36