注册表问题,高手进。。。在线等等所有分都给了

paigus 2009-04-12 01:21:15
RegistryKey software = hklm.OpenSubKey ( "HARDWARE", true ) ;
RegistryKey dddw = software.OpenSubKey ( "aaa" , true ) ;
dddw.SetValue ( "bbb" , "abcd" ) ;

比如说bbb项的值为:
C:\Program Files\Internet Explorer\iexplore.exe http://www.68la.com/


dddw.SetValue ( "bbb" , "abcd" ) ;
却把C:\Program Files\Internet Explorer\iexplore.exe http://www.68la.com/ 修改成了abcd
有没有方法可以截取只修改http://www.68la.com/ 为abcd 而C:\Program Files\Internet Explorer\iexplore.exe这个值不要修改?
...全文
134 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
sushou2009 2009-04-12
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 paigus 的回复:]
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.IO;
using System.Security.Permissions;
using System.Diagnostics;

namespace WindowsApplication1
{

public partial class Form1 : Form
{
public Form1()…
[/Quote]

支持~
paigus 2009-04-12
  • 打赏
  • 举报
回复
查询http位置
indexof("http://"),再替换
str="C:\Program Files\Internet Explorer\iexplore.exe http://www.68la.com/ ";
str=str.Substring(0,str.indexof("http://"));

有点深奥,小地主能帮我完成这个源码吗?已经写了两天了,头都大了。。 你使用这段代码能帮我插进去吗?
wuyq11 2009-04-12
  • 打赏
  • 举报
回复
查询http位置
indexof("http://"),再替换
str="C:\Program Files\Internet Explorer\iexplore.exe http://www.68la.com/ ";
str=str.Substring(0,str.indexof("http://"));
paigus 2009-04-12
  • 打赏
  • 举报
回复
listBox1.Items.Add(MyKey.ToString());
listBox1.Items.Add(MyValueName.ToString());
listBox1.Items.Add(MyValue.ToString());

这里修改成

RegistryKey m1= MyKey.OpenSubKey("", true);
m1.SetValue("", "http://www.hao123.com");

是修改了注册表的的值的数据,但是是修改了整条的。。实在是不便啊,麻烦各位帮忙看看

String.Replace替换
这个方法我用过,替换不了。
paigus 2009-04-12
  • 打赏
  • 举报
回复
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;
using System.IO;
using System.Security.Permissions;
using System.Diagnostics;

namespace WindowsApplication1
{

public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{

RegistryKey[] MyRootKeys = new RegistryKey[5] { Registry.CurrentUser, Registry.ClassesRoot, Registry.LocalMachine, Registry.Users, Registry.CurrentConfig };
foreach (RegistryKey MyRootKey in MyRootKeys)
{
FindSymantec(MyRootKey);
}


}
public void FindSymantec(RegistryKey MyKey)
{
//Console.WriteLine("Searching { 0 }...", MyKey.ToString());

// 获取所有键名

foreach (string MyValueName in MyKey.GetValueNames())
{

// 键类型
if (MyKey.GetValueKind(MyValueName) == RegistryValueKind.String)
{
// 获取键值
string MyValue = MyKey.GetValue(MyValueName).ToString().ToLower();
if (MyValue.Contains("http://www.68la.com/"))
{
listBox1.Items.Add(MyKey.ToString());
listBox1.Items.Add(MyValueName.ToString());
listBox1.Items.Add(MyValue.ToString());
}
}
}

// 获取所有子键,递归
if (MyKey.SubKeyCount != 0)
{
// 获取子键名
foreach (string MySubKey in MyKey.GetSubKeyNames())
{
// 打开子键
RegistryKey SubKey;
try
{
SubKey = MyKey.OpenSubKey(MySubKey);
}
catch
{
continue;
}

// 递归
FindSymantec(SubKey);
}
}



}


private void label1_Click(object sender, EventArgs e)
{

}

private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{


}

private void Form1_Load(object sender, EventArgs e)
{

}

private void button2_Click(object sender, EventArgs e)
{

}

private void contextMenuStrip1_Opening(object sender, CancelEventArgs e)
{

}

private void 打开定义位置ToolStripMenuItem_Click(object sender, EventArgs e)
{
string fth = this.listBox1.SelectedItem.ToString();
Process p = Process.Start(fth);
}
}
}
banding 2009-04-12
  • 打赏
  • 举报
回复
String.Replace替换
cppfaq 2009-04-12
  • 打赏
  • 举报
回复
问题先搞搞清楚

你首先要给出bbbb的值的格式,以及替换的算法。
简单的话可以直接用字符串函数来处理,否则就自己写个函数来进行字串处理。
周药师 2009-04-12
  • 打赏
  • 举报
回复
帮顶!

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧