修改注册表
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);
}
}
弱弱的问一下这一段
[DllImport(@"wininet",
SetLastError = true,
CharSet = CharSet.Auto,
EntryPoint = "InternetSetOption",
CallingConvention = CallingConvention.StdCall)]
在上面的代码是什么作用,什么意思
还有下面的两句
InternetSetOption(0, 39, IntPtr.Zero, 0);
InternetSetOption(0, 37, IntPtr.Zero, 0);
是如何激活设置的
public static extern bool InternetSetOption
(
int hInternet,
int dmOption,
IntPtr lpBuffer,
int dwBufferLength
);这里只提供了个函数签名,没有提供函数实现,为什么?
各位大侠,谢了