dotnet-Snippets.com
Snippets: 61 | Registered User: 61 | Visitors online: 14
Main Menu

Home
Random Snippet
FAQs
Contact Us
Imprint
RSS Feeds

Rss All languages
Rss C#
Rss VB.NET
Rss C++
Rss J#
Rss ASP.NET
Google Ads

Sri Lanka .NET 
                Forum Member
Add/Remove registry entries for windows startup.

Author: Guest
Programming Language: C# Rating:
not yet rated

Views: 2897

Description:

Add/Remove registry entries for windows startup.



C#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/// <summary>
/// Add/Remove registry entries for windows startup.
/// </summary>
/// <param name="AppName">Name of the application.</param>
/// <param name="enable">if set to <c>true</c> [enable].</param>
private void SetStartup(string AppName, bool enable)
{
    string runKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run";

    Microsoft.Win32.RegistryKey startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey);
   
    if (enable)
    {
        if (startupKey.GetValue(AppName) == null)
        {
            startupKey.Close();
            startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey, true);
            // Add startup reg key
            startupKey.SetValue(AppName, Application.ExecutablePath.ToString());
            startupKey.Close();
        }
    }
    else
    {
        // remove startup
        startupKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(runKey, true);
        startupKey.DeleteValue(AppName, false);
        startupKey.Close();
    }
}

This Snippets could be interesting for you:

Poor Excellent
1 2 3 4 5 6 7 8 9 10
Sign in to vote for this snippet.

Comments:
(Please log in to wrtite an comment.)