C# 修改注册表

本文提供了一个C#程序示例,用于自动修复Windows系统的注册表设置。主要包括:禁用HTTP1.1代理连接,并将Internet区域的安全级别设置为中。这些操作通过直接修改注册表键值实现。
static void Main(string[] args) { Console.Title = "修复注册表"; try { //高级---通过HTTP 1.1设置 通过代理连接使用 HTTP 1.1√去掉 RegistryKey rkey = Registry.CurrentUser.OpenSubKey(@"Software//Microsoft//Windows//CurrentVersion//Internet Settings", true); rkey.SetValue("ProxyHttp1.1", "dword:00000001"); //修改安全级别为中 RegistryKey rkey1 = Registry.CurrentUser.OpenSubKey(@"Software//Microsoft//Windows//CurrentVersion//Internet Settings//Zones//3", true); rkey1.SetValue("CurrentLevel", "69632", RegistryValueKind.DWord); //rkey1.SetValue("1001", "00000001", RegistryValueKind.DWord); //rkey1.SetValue("1200", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1400", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1402", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1405", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1407", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1604", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1604", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1606", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1607", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1608", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1800", "00000001", RegistryValueKind.DWord); //rkey1.SetValue("1802", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1803", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1804", "00000001", RegistryValueKind.DWord); //rkey1.SetValue("1A00", "00020000", RegistryValueKind.DWord); //rkey1.SetValue("1A00", "131072", RegistryValueKind.DWord); //rkey1.SetValue("1A02", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1A03", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1A05", "00000001", RegistryValueKind.DWord); //rkey1.SetValue("1A06", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("1C00", "65536", RegistryValueKind.DWord); //rkey1.SetValue("1E05", "131072", RegistryValueKind.DWord); //rkey1.SetValue("2100", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("2101", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("2000", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("2004", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("2001", "00000000", RegistryValueKind.DWord); //rkey1.SetValue("2007", "65536", RegistryValueKind.DWord); } catch (System.Exception e) { Console.WriteLine(e.ToString()); } Console.WriteLine("修复完成!请按任意键退出."); Console.ReadKey(); }
去年年末才看过一本关于ASP.NET 操作注册表的书,可惜那时候就压根没想过写到网上去。 现在想想 写到网上有诸多好处 比如、 1、可以快速回忆相关知识点,还有自己写的参考代码,比别人写的强多了 2、可以丰富自己的博客推广自己 3、加强自己写作能力 贴出代码了 -------------------- 1、引入命名空间 using Microsoft.Win32;//修改注册表所需要用到的命名空间 2、之后方法喽 //修改注册表 设置IE打印背景图片 适用于IE8一下版本,修改为工具选项下的 打印背景颜色与图像 public void IESetupPrint_Background() { RegistryKey key = Registry.CurrentUser; RegistryKey software = key.OpenSubKey("Software\\Microsoft\\Internet Explorer\\Main", true); //该项必须已存在 software.SetValue("Print_Background", "yes"); software.Close(); } //设置页眉 页脚为空 public void IESetupPageSetup() { RegistryKey key = Registry.CurrentUser; RegistryKey software = key.OpenSubKey("Software\\Microsoft\\Internet Explorer\\PageSetup", true); //该项必须已存在 software.SetValue("header", ""); software.SetValue("footer", ""); software.Close(); } //设置页边距 设置IE页面设置 打印背景图片 //上下边距具体的值可以 先在IE里面设置再查看注册表实际值 然后在程序里写死 public void IESetupPage() { RegistryKey key = Registry.CurrentUser;//IE8以上版本 修改为页面设置 里页面 打印背景颜色与图像 RegistryKey software = key.OpenSubKey("Software\\Microsoft\\Internet Explorer\\PageSetup", true); software.SetValue("margin_top", 0.55984); software.SetValue("margin_bottom", 0.55984); software.SetValue("margin_left", 0.75433); software.SetValue("margin_right", 0.40000); software.SetValue("Print_Background", "yes"); } //查看注册表相应的键值 运行输入 regedit
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值