OKIEWARDOYO

C#.NET No.36 - 7 full

Oct 3rd, 2013
1,994
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. //gunakan directive ini terlebih dahulu
  11. using Microsoft.Win32;
  12.  
  13. namespace StartUpApp
  14. {
  15.     public partial class Form1 : Form
  16.     {
  17.         RegistryKey rk = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
  18.  
  19.         //atau bisa juga pakai di bawah ini untuk run pada semua user yang login
  20.         //
  21.         //ganti CurrentUser dengan LocalMachine
  22.         //RegistryKey rk = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
  23.  
  24.         public Form1()
  25.         {
  26.             InitializeComponent();
  27.  
  28.             //kita akan mengecek apakah sudah jalan di startup atau belum
  29.             if (rk.GetValue("StartUpApp") == null)
  30.             {
  31.                 checkBoxStartUp.Checked = false;
  32.             }
  33.             else
  34.             {
  35.                 checkBoxStartUp.Checked = true;
  36.             }
  37.  
  38.         }
  39.  
  40.         private void buttonClose_Click(object sender, EventArgs e)
  41.         {
  42.             if (checkBoxStartUp.Checked == true)
  43.             {
  44.                 rk.SetValue("StartUpApp", Application.ExecutablePath.ToString());
  45.             }
  46.             else
  47.             {
  48.                 rk.DeleteValue("StartUpApp", false);
  49.             }
  50.  
  51.             Close();
  52.         }
  53.  
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment