日期:2014-05-17  浏览次数:20696 次

winform程序开机自启动
我做了一个winform的小程序,是一个工作任务管理小程序,现在我想要增加一个功能,就是类似QQ或MSN那样的,在登录界面上添加两个CheckBox,一个是“开机启动”,一个是“自动登录” 想要实现开机自动启动程序并自动登录。请各位给出出主意呢! 我用的是VS2008+SQL server2005 开发语言是C#

------解决方案--------------------
string KJLJ = Application.ExecutablePath;

            if (!System.IO.File.Exists(KJLJ))//判断指定文件是否存在

                return;

            string newKJLJ = KJLJ.Substring(KJLJ.LastIndexOf("\\") + 1);

            RegistryKey Rkey =

                Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

            if (Rkey == null)

                Rkey = Registry.LocalMachine.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");

            Rkey.SetValue(newKJLJ, KJLJ);

            MessageBox.Show("程序设置完毕,请重新启动计算机后即可生效!", "程序员的爬行温馨提醒", MessageBoxButtons.OK, MessageBoxIcon.Information);