Posts Tagged ‘CSharp’

C# Autostart

Montag, August 30th, 2010

 
 

  1. Prüfen ob eine Anwendung im Autostart eingetragen ist

    public static bool RunOnStartupCurrentUser( string applicationName )
         {
             RegistryKey regkey = Registry.CurrentUser.OpenSubKey
                 ( “SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run”true );
             if ( regkey.GetValue(applicationName) == null )
                 {
                 return false;
                 }
             else
                 {
                 return true;
                 }
         }

 
 

  1. Anwendung in der registry eintragen

    public static void AddCurrentUser(string executablePath, string applicationName)
        {
           RegistryKey regkey = Registry.CurrentUser.OpenSubKey
                ( “SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run”true );
            regkey.SetValue( applicationName, executablePath );
        }

     
     

  2. Anwendung aus der Registry löschen

    public static void RemoveCurrentUser(string applicationName)
        {
        RegistryKey regkey = Registry.CurrentUser.OpenSubKey
            ( “SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run”true );
        regkey.DeleteValue(applicationName,true);
        }

 
 

Mit msconfig.exe last sich dann auch noch recht einfach prüfen ob

die Werte wirklich eingetragen wurden.

Mehr gibt es nicht zu tun.

Share and Enjoy:
  • Print
  • Facebook
  • Twitter
  • Google Bookmarks
  • Live
  • PDF

Form auf Tray Icon Minimieren

Montag, März 8th, 2010

Wir benötigen 3 Events.

Eins beim “resize” des Fensters:


private void frmMain_Resize(object sender, EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
                Hide();
}

Eins beim “DoubleClick” auf das Icon:


private void notifyIcon_DoubleClick(object sender, EventArgs e)
{
if (FormWindowState.Minimized == WindowState)
{
                Show();
                WindowState = FormWindowState.Normal;
}
else
{
                Hide();
                WindowState = FormWindowState.Minimized;
}
}

Und zum schluss noch ein Event beim schliesen des Forms:
(Das muss nicht sein, aber es ist schöner wenn das Icon gleich aus dem tray verschwindet)


private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
            notifyIcon.Visible = false;
}

Share and Enjoy:
  • Print
  • Facebook
  • Twitter
  • Google Bookmarks
  • Live
  • PDF