Home > Backend Development > C++ > How Can I Make My C# Application Automatically Start with Windows?

How Can I Make My C# Application Automatically Start with Windows?

DDD
Release: 2025-01-02 14:02:39
Original
472 people have browsed it

How Can I Make My C# Application Automatically Start with Windows?

How to Configure Automatic Startup for a Program

Question:

How can I configure a program to launch automatically when Windows starts?

Details:

  • I have a small application that includes a checkbox allowing users to choose whether it should start with Windows.
  • I am using C# with .NET 2.0.

Answer:

To set a program to run at startup, you can add a registry key to the "Run" folder of the current user:

using Microsoft.Win32;
private void SetStartup()
{
    RegistryKey rk = Registry.CurrentUser.OpenSubKey
        ("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", true);

    if (chkStartUp.Checked)
        rk.SetValue(AppName, Application.ExecutablePath);
    else
        rk.DeleteValue(AppName,false);            

}
Copy after login
  • chkStartUp is the checkbox that the user can toggle to set the startup option.
  • AppName is a string identifier for the application.
  • Application.ExecutablePath is the file path of the application's executable file.

This registry setting will cause the program to launch automatically when the user logs into Windows. The checkbox in your application's UI will allow users to easily enable or disable this behavior.

The above is the detailed content of How Can I Make My C# Application Automatically Start with Windows?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template