在button中运行
string StartupPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Startup);
System.IO.File.Copy("E://BroadcastCtrl//bin//Debug//BroadcastCtrl.exe", StartupPath + "BroadcastCtrl.exe", true);
//获得文件的当前路径
string dir = Directory.GetCurrentDirectory();
//获取可执行文件的全部路径
string exeDir = "E:l//BroadcastCtrl//bin//Debug//" + "BroadcastCtrl.exe";//这句是关键,这句就能实现开机运行。运行程序的完全路径
//获取Run键
RegistryKey key1 = Registry.LocalMachine;
RegistryKey key2 = key1.CreateSubKey("SOFTWARE");
RegistryKey key3 = key2.CreateSubKey("Microsoft");
RegistryKey key4 = key3.CreateSubKey("Windows");
RegistryKey key5 = key4.CreateSubKey("CurrentVersion");
RegistryKey key6 = key5.CreateSubKey("Run");
//在Run键中写入一个新的键值
key6.SetValue("myForm", exeDir);
key6.Close();
//如果要取消的话就将key6.SetValue("myForm",exeDir);改成
//key6.SetValue("myForm",false);
//key6.Close();
6015

被折叠的 条评论
为什么被折叠?



