Computer/C# Updated: 2020. 6. 30. 14:30 hwaya.

시작 프로그램 등록

반응형
public Form1()
{
    InitializeComponent();
    btnAdd.Click += new EventHandler(btnAdd_Click);
    btnRemove.Click += new EventHandler(btnRemove_Click);
}
 
void btnAdd_Click(object sender, EventArgs e)
{	// 시작 프로그램 등록
    try
    {
        // 시작프로그램 등록하는 레지스트리
        string runKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
        RegistryKey strUpKey = Registry.LocalMachine.OpenSubKey(runKey);
        if (strUpKey.GetValue("StartupTest") == null)
        {
            strUpKey.Close();
            strUpKey = Registry.LocalMachine.OpenSubKey(runKey, true);
            // 시작프로그램 등록명과 exe경로를 레지스트리에 등록
            strUpKey.SetValue("StartupTest", Application.ExecutablePath);
        }
        MessageBox.Show("Add Startup Success");
    }
    catch
    {
        MessageBox.Show("Add Startup Fail");
    }
}
 
void btnRemove_Click(object sender, EventArgs e)
{	// 시작프로그램 제거
    try
    {
        string runKey = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
        RegistryKey strUpKey = Registry.LocalMachine.OpenSubKey(runKey, true);
        // 레지스트리값 제거
        strUpKey.DeleteValue("StartupTest");
        MessageBox.Show("Remove Startup Success");
    }
    catch
    {
        MessageBox.Show("Remove Startup Fail");
    }
}
반응형

Table of Contents


    EIGHTBOX
    EIGHTBOX
    hwaya.

    programmer

    🍋일상의 소소한 순간들부터 큰 꿈까지, 호기심을 만족시킬 다양한 카테고리를 담은 블로그 입니다. 그리고, 소소한 행동에 감동하며 기뻐하고 하루하루에 감사하는 사람🌵

    Today Yesterday Total
    최신글