您的位置:首页 > 编程语言 > C#

C#修改注册表(IE),

2008-03-11 11:45 483 查看
C#修改注册表(IE),以修改IE代理服务器为例:

using System;
using System.Collections;
using System.Threading;
using System.Runtime.InteropServices;
using System.Diagnostics;
using Microsoft.Win32;

namespace TestBlog
{
    class Program
    {
        [DllImport(@"wininet",
        SetLastError = true,
        CharSet = CharSet.Auto,
        EntryPoint = "InternetSetOption",
        CallingConvention = CallingConvention.StdCall)]

        public static extern bool InternetSetOption
        (
        int hInternet,
        int dmOption,
        IntPtr lpBuffer,
        int dwBufferLength
        );

        public static void SetProxy(string proxy)
        {
            //打开注册表
            RegistryKey regKey = Registry.CurrentUser;
            string SubKeyPath = @"Software/Microsoft/Windows/CurrentVersion/Internet Settings";
            RegistryKey optionKey = regKey.OpenSubKey(SubKeyPath, true);
            //更改健值,设置代理,
            optionKey.SetValue("ProxyEnable", 1);
            optionKey.SetValue("ProxyServer", proxy);

            //激活代理设置
            InternetSetOption(0, 39, IntPtr.Zero, 0);
            InternetSetOption(0, 37, IntPtr.Zero, 0);
        }

    }

文章引用自:

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息