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这个值不要修改?

解决方案 »

  1.   

    问题先搞搞清楚你首先要给出bbbb的值的格式,以及替换的算法。
    简单的话可以直接用字符串函数来处理,否则就自己写个函数来进行字串处理。
      

  2.   

    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);
            }
        }
    }
      

  3.   

              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替换
    这个方法我用过,替换不了。
      

  4.   

    查询http位置
    indexof("http://"),再替换
    str="C:\Program Files\Internet Explorer\iexplore.exe http://www.68la.com/ ";
    str=str.Substring(0,str.indexof("http://"));
      

  5.   

    查询http位置 
    indexof("http://"),再替换 
    str="C:\Program Files\Internet Explorer\iexplore.exe http://www.68la.com/ "; 
    str=str.Substring(0,str.indexof("http://")); 有点深奥,小地主能帮我完成这个源码吗?已经写了两天了,头都大了。。 你使用这段代码能帮我插进去吗?