Change system proxy settings with C++ Windows API

This commit is contained in:
Connection Refused
2020-01-29 19:48:02 +08:00
parent 12275321a2
commit b24689ba25
2 changed files with 35 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ namespace Netch
/// <param name="index">适配器索引</param>
/// <param name="metric">跃点数</param>
/// <returns>是否成功</returns>
[DllImport("bin\\NetchCore.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "CreateRoute")]
[DllImport("bin\\NetchCore", CallingConvention = CallingConvention.Cdecl, EntryPoint = "CreateRoute")]
public static extern bool CreateRoute(string address, int netmask, string gateway, int index, int metric = 0);
/// <summary>
@@ -25,7 +25,7 @@ namespace Netch
/// <param name="index">适配器索引</param>
/// <param name="metric">跃点数</param>
/// <returns>是否成功</returns>
[DllImport("bin\\NetchCore.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ChangeRoute")]
[DllImport("bin\\NetchCore", CallingConvention = CallingConvention.Cdecl, EntryPoint = "ChangeRoute")]
public static extern bool ChangeRoute(string address, int netmask, string gateway, int index, int metric = 0);
/// <summary>
@@ -37,7 +37,31 @@ namespace Netch
/// <param name="index">适配器索引</param>
/// <param name="metric">跃点数</param>
/// <returns>是否成功</returns>
[DllImport("bin\\NetchCore.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "DeleteRoute")]
[DllImport("bin\\NetchCore", CallingConvention = CallingConvention.Cdecl, EntryPoint = "DeleteRoute")]
public static extern bool DeleteRoute(string address, int netmask, string gateway, int index, int metric = 0);
/// <summary>
/// 设置直连
/// </summary>
/// <returns>是否成功</returns>
[DllImport("bin\\sysproxy", CallingConvention = CallingConvention.Cdecl)]
public static extern bool SetDIRECT();
/// <summary>
/// 设置全局
/// </summary>
/// <param name="remote">地址</param>
/// <param name="bypass">绕过</param>
/// <returns>是否成功</returns>
[DllImport("bin\\sysproxy", CallingConvention = CallingConvention.Cdecl)]
public static extern bool SetGlobal([MarshalAs(UnmanagedType.LPTStr)] string remote, [MarshalAs(UnmanagedType.LPTStr)] string bypass);
/// <summary>
/// 设置自动代理
/// </summary>
/// <param name="remote">URL</param>
/// <returns>是否成功</returns>
[DllImport("bin\\sysproxy", CallingConvention = CallingConvention.Cdecl)]
public static extern bool SetURL([MarshalAs(UnmanagedType.LPTStr)] string remote);
}
}