码迷,mamicode.com
首页 > Windows程序 > 详细

C# 开机自动启动程序

时间:2015-03-10 11:40:16      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

原文:C# 开机自动启动程序

新建一个winform拖一个checkbox进来。。

然后设置它的changed事件。

已经测试过,可以直接复制使用。

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            if (checkBox1.Checked) //设置开机自启动  
            {
                MessageBox.Show ("设置开机自启动,需要修改注册表","提示");  
                string path = Application.ExecutablePath;
                RegistryKey rk = Registry.LocalMachine;
                RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
                rk2.SetValue("JcShutdown", path);
                rk2.Close();
                rk.Close();
            }
            else //取消开机自启动  
            {
                MessageBox.Show ("取消开机自启动,需要修改注册表","提示");  
                string path = Application.ExecutablePath;
                RegistryKey rk = Registry.LocalMachine;
                RegistryKey rk2 = rk.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
                rk2.DeleteValue("JcShutdown", false);
                rk2.Close();
                rk.Close();
            }  
        }

C# 开机自动启动程序

标签:

原文地址:http://www.cnblogs.com/lonelyxmas/p/4325262.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!