Willkommen bei dotnet-snippets.de! Snippet hinzufügen Login Registrieren
Snippets in der Datenbank: 1562 | Anzahl registrierter User: 1893 | Besucher online: 368
Hauptmenü
Home
Top Ten
Zufälliger Snippet
FAQs
.NET Community
dotnet-forum.de
dotnet-kicks.de
Social

RSS Feeds
Rss Alle Snippets
Rss C#
Rss VB.NET
Rss C++
Rss ASP.NET
Partner
Member of Microsoft Community Leader/Insider Program (CLIP)

Add/Remove registry entries for windows startup.


Autor: Gast
Sprache: C#
Bewertung:
noch nicht bewertet
Anzahl der Aufrufe: 11473
  
Kick it on dotnet-kicks.de  

Beschreibung:

Add/Remove registry entries for windows startup.

Abgelegt unter: Registry, Autostart.



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();
    }
}
Sie haben Fragen zu diesem Snippet oder brauchen Hilfe bei der .NET Entwicklung?
Freundliche und kompetente Entwickler helfen Ihnen gern weiter im Forum für .NET Entwicklung.



Kommentare:
(Zum Schreiben von Kommentaren bitte anmelden.)



schlecht sehr gut
1 2 3 4 5 6 7 8 9 10
Nur angemeldete User können Snippets bewerten.