Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a C# application at Windows startup?

I made an application that launches during startup, with the next code below.
The process runs on the process manager tool after the restart, but I can't see the application on the screen. When I open the same .exe file from the startup registry value the program runs perfect.

// The path to the key where Windows looks for startup applications RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);  // Add the value in the registry so that the application runs at startup rkApp.SetValue("MyApp", Application.ExecutablePath.ToString()); 

What can I do to fix it up?

like image 411
Oded .S Avatar asked Feb 23 '11 10:02

Oded .S


People also ask

What should you run your AC at?

According to the Department of Energy1, 78° Fahrenheit is the sweet spot for air conditioners to balance energy savings and comfort when people are at home and need cooling.

How do I start my AC for the first time?

For most central air systems, the process is simple. Simply move the switch on your thermostat from “Heat” to “Cool”. If your system was off entirely, you may need to move the switch from “Off” to “Cool” instead. Once you turn your system on, be sure to close any open windows to conserve energy.


2 Answers

Code is here (Win form app):

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using Microsoft.Win32;  namespace RunAtStartup {     public partial class frmStartup : Form     {         // The path to the key where Windows looks for startup applications         RegistryKey rkApp = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);          public frmStartup()         {             InitializeComponent();             // Check to see the current state (running at startup or not)             if (rkApp.GetValue("MyApp") == null)             {                 // The value doesn't exist, the application is not set to run at startup                 chkRun.Checked = false;             }             else             {                 // The value exists, the application is set to run at startup                 chkRun.Checked = true;             }         }          private void btnOk_Click(object sender, EventArgs e)         {             if (chkRun.Checked)             {                 // Add the value in the registry so that the application runs at startup                 rkApp.SetValue("MyApp", Application.ExecutablePath);             }             else             {                 // Remove the value from the registry so that the application doesn't start                 rkApp.DeleteValue("MyApp", false);             }         }     } } 
like image 88
Adrew Avatar answered Oct 16 '22 22:10

Adrew


Try this code:

private void RegisterInStartup(bool isChecked) {     RegistryKey registryKey = Registry.CurrentUser.OpenSubKey             ("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);     if (isChecked)     {         registryKey.SetValue("ApplicationName", Application.ExecutablePath);     }     else     {         registryKey.DeleteValue("ApplicationName");     } } 

Source (dead): http://www.dotnetthoughts.net/2010/09/26/run-the-application-at-windows-startup/

Archived link: https://web.archive.org/web/20110104113608/http://www.dotnetthoughts.net/2010/09/26/run-the-application-at-windows-startup/

like image 37
Anuraj Avatar answered Oct 16 '22 22:10

Anuraj