以下程序,为什么运行后在注册表里却看不到我的程序. public static bool SetAutoRun(string keyName, string filePath)
{
try
{
RegistryKey runKey = Registry.LocalMachine.OpenSubKey Microsoft\Windows\CurrentVersion\Run", true);
runKey.SetValue(keyName, filePath);
runKey.Close();
}
catch
{
return false;
}
return true;
} private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
SetAutoRun("myexe", "d:\\notepad.exe");
//SetAutoRun("myexe", "d:\notepad.exe"); }
{
try
{
RegistryKey runKey = Registry.LocalMachine.OpenSubKey Microsoft\Windows\CurrentVersion\Run", true);
runKey.SetValue(keyName, filePath);
runKey.Close();
}
catch
{
return false;
}
return true;
} private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
SetAutoRun("myexe", "d:\\notepad.exe");
//SetAutoRun("myexe", "d:\notepad.exe"); }
解决方案 »
- 统计二叉树内边的数量
- C# 如何得到下午的时间 (24小时制)
- Richtextbox着色时的一个大缺陷
- 找高人 关于用C# 编程 !@!!!!!!!!!!! 与EXCHANGE有关
- 如何判断一个平面中有黑象素点??
- 窗体最小化以后,如果有新消息,怎样让它在任务栏上闪烁提示呢?
- C# 判断字符串为时间~~~~~~在线等
- 怎样实现递归删除
- c#怎么调用自己用vb编写的dll组件
- windows form's keyboard event
- 求一个C# 的web框架源码或链接,找了一上午居然没找到可可用的,功能一般即可,不能有dll的 [C#]
- 将DataSet数据修改后保存到XML文件,保存后总是在XML文件中出现多余的代码,请高手指教?
这是什么啊
RegistryKey runKey = Registry.LocalMachine.OpenSubKey("@Microsoft\Windows\CurrentVersion\Run", true);
是这样写吧
{
try
{
RegistryKey runKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\", true);
{
foreach(string site in myRKCN.GetValueNames())
{
if(site==keyName)
{
myRKCN.DeleteValue(site,false);
myRKCN.SetValue(keyName,filePath);
}
}
}
}
catch
{
return false;
}
return true;
} private void button1_Click(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
SetAutoRun("myexe", "d:\\notepad.exe");
//SetAutoRun("myexe", "d:\notepad.exe"); }
。。、。
if后再加个
else
{
myRKCN.SetValue(keyName,filePath);
}
这是代码,是成功的啊 public static void SetAutoRun(string keyName, string filePath)
{
try
{
RegistryKey runKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run\", true);
{
//foreach (string site in runKey.GetValueNames())
//{
// if (site == keyName)
// {
// runKey.DeleteValue(site, false);
// runKey.SetValue(keyName, filePath);
// MessageBox.Show("添加成功!");
// }
// else
// {
runKey.SetValue(keyName, filePath);
MessageBox.Show("添加成功!");
//}
//}
}
}
catch
{ }
} private void button1_Click(object sender, EventArgs e)
{
SetAutoRun("myexe", "d:\\notepad.exe");
}同时倒入using Microsoft.Win32;命名空间
省略的那部分是因为我的注册表run下根本没myexe这一项,所以我也不用不遍历这个目录,直接添加了,
最后是成功的啊
if (checkBox1.Checked == true) 这里,我不明白这是什么,
也不清楚你为什么要将SetAutoRun方法返回bool类型
你看着改吧,我试验了3遍都是对的,
我要下线了,晚上9点以后再上,
如果有人解答了或你知道怎么回事了那就算了
如果还不知道,晚上再说或加我MSN:[email protected]
再见!