现在正在制作一个物资公司的管理软件,把自己掌握的学到的一点点细细的讲给喜欢C#的同仁们,互相交流。</span>
想要给你制作的应用程序做一个开机启动,很方便,你可以让用户选择,在你的工具栏中的某个下拉菜单里添加一个“开机启动”,你想练习的话,也可以只先设置一个按钮即可。<br />
首先你要添加两个命名空间,这是必须的啊。</span>
using Microsoft.Win32;
using System.IO;
然后在你的按钮单击事件里加入如下即可
private void 开机启动KToolStripMenuItem_Click(objectsender, EventArgs e)
{
//从这里开始复制
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);
//到这里结束,试一试,无需修改,即可,呵呵,不过你也要努力学习啊
}