How to make an Application auto run on Windows startup in C#
By FoxLearn 7/16/2024 9:07:18 AM 17.11K
Open your Visual Studio, then click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "AutorunStartup" and then click OK button.
How to make an Application auto run on Windows startup in C#
To make an application automatically run on Windows startup in C#, you can add an entry to the Windows registry.
Here's a basic example of how you can do this.
Drag and drop Button controls from Visual Studio onto your form designer, then design your form as shown below
Add a click event handler to the Setup button that allows you to set value to your registry
private void button1_Click(object sender, EventArgs e) { //Open the registry key for startup programs, create a registry key, then save your program path RegistryKey reg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true); // Specify the name and path of your application executable, add the application to the startup reg.SetValue("My application", Application.ExecutablePath.ToString()); MessageBox.Show("You have been successfully saved.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); }
This code will add a registry entry under HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
. When Windows starts up, it will look at this registry location and automatically launch any applications listed there.
VIDEO TUTORIAL
- How to Print Text in a Windows Form Application Using C#
- How to fill ComboBox and DataGridView automatically in C#
- How to Read text file and Sort list in C#
- How to pass ListView row data into another Form in C#
- How to read and write to text file in C#
- How to make a Countdown Timer in C#
- How to Display selected Row from DataGridView to TextBox in C#
- How to Get all Forms and Open Form with Form Name in C#