Home > Backend Development > C++ > How Can I Make My C# Application Launch Automatically at Windows Startup?

How Can I Make My C# Application Launch Automatically at Windows Startup?

Susan Sarandon
Release: 2025-01-04 08:20:38
Original
846 people have browsed it

How Can I Make My C# Application Launch Automatically at Windows Startup?

Startup Program: Setting Application Launch at System Boot

The challenge of automatically launching an application at Windows startup can be tackled effectively. A user sought guidance in achieving this from within a C# application, featuring a user-configurable checkbox.

The solution requires a careful manipulation of the registry. The user opted for a registry key addition to the current user's "Run" folder, as suggested by Joel. The code snippet below showcases the implementation:

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

In this code:

  • The SetStartup method handles the checkbox interaction.
  • Registry manipulation actions are performed using the RegistryKey class.
  • The "Run" folder key is opened/created for write access.
  • Based on the checkbox state, an appropriate registry value is set or deleted.

The above is the detailed content of How Can I Make My C# Application Launch Automatically at Windows Startup?. 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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template