Home >Backend Development >C++ >How Can I Automatically Launch a C# .NET 2.0 Application on Windows Startup?

How Can I Automatically Launch a C# .NET 2.0 Application on Windows Startup?

DDD
DDDOriginal
2025-01-04 13:31:39660browse

How Can I Automatically Launch a C# .NET 2.0 Application on Windows Startup?

Implementing Automatic Application Launch at Startup

Users often desire seamless access to essential applications on system startup. To address this requirement, developers can incorporate settings that allow users to enable automatic launch at startup. This article will delve into how to implement this functionality using C# and the .NET 2.0 framework.

The provided code utilizes the RegistryKey class to manipulate the registry and modify the "Run" folder, which houses shortcuts to applications that launch automatically at startup.

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);            
}
  • Registry.CurrentUser.OpenSubKey retrieves the "Run" registry key within the current user's hive.
  • The Checked property of the chkStartUp checkbox determines whether the application should be launched at startup.
  • If enabled, the SetValue method adds an entry to the "Run" registry key with the application's name and executable path.
  • If disabled, the DeleteValue method removes the previously set entry.

The above is the detailed content of How Can I Automatically Launch a C# .NET 2.0 Application on Windows Startup?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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