使用Registry类修改注册表(以修改IE首页为例):
1.引入命名空间 using Microsoft.win32;
2.选择基选项 CurrentUser,再用OpenSubKey(str,true)方法打开指定路径str的项级节点,这里str为"Software\\Microsoft\\Internet Explorer\\Main",只有第一参数时OpenSubKey是以只读方式打开,这里我们设置第二参数为true。
RegistryKey registry = Registry.CurrentUser.OpenSubKey(
"Software\\Microsoft\\Internet Explorer\\Main", true);
3.SetValue方法修改(key,value)值,如果当前路径没有此key则自动新建一个key其值为value。
registry.SetValue("Start Page", "www.163.com");修改成功 - -
1.引入命名空间 using Microsoft.win32;
2.选择基选项 CurrentUser,再用OpenSubKey(str,true)方法打开指定路径str的项级节点,这里str为"Software\\Microsoft\\Internet Explorer\\Main",只有第一参数时OpenSubKey是以只读方式打开,这里我们设置第二参数为true。
RegistryKey registry = Registry.CurrentUser.OpenSubKey(
"Software\\Microsoft\\Internet Explorer\\Main", true);
3.SetValue方法修改(key,value)值,如果当前路径没有此key则自动新建一个key其值为value。
registry.SetValue("Start Page", "www.163.com");修改成功 - -