robert
robert

Reputation: 321

turn off the proxy c#

this is the code to turn on the proxy:

Public struct Struct_INTERNET_PROXY_INFO 
{ 
    public int dwAccessType; 
    public IntPtr proxy; 
    public IntPtr proxyBypass; 
}; 

[DllImport("wininet.dll", SetLastError = true)] 
private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);

private void RefreshIESettings(string strProxy) 
{ 
    const int INTERNET_OPTION_PROXY = 38; 
    const int INTERNET_OPEN_TYPE_PROXY = 3; 

    Struct_INTERNET_PROXY_INFO struct_IPI; 

    // Filling in structure 
    struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY; 
    struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy); 
    struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local"); 

    // Allocating memory 
    IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI)); 

    // Converting structure to IntPtr 
    Marshal.StructureToPtr(struct_IPI, intptrStruct, true); 

    bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI)); 
} 

private void SomeFunc() 
{ 
    RefreshIESettings("192.168.1.200:1010"); 

    System.Object nullObject = 0; 
    string strTemp = String.Empty; 
    System.Object nullObjStr = strTemp;
    axWebBrowser1.Navigate("http://willstay.tripod.com", ref nullObject, ref nullObjStr, ref nullObjStr, ref nullObjStr); 
}

but how can i turn off?????? thanks

Upvotes: 1

Views: 3093

Answers (3)

Birol İnci
Birol İnci

Reputation: 81

Change RefreshIESettings like this code block. Just call this code like this. RefreshIESettings(":")

public static void RefreshIESettings(string strProxy)
{
    const int INTERNET_OPTION_PROXY = 38;
    const int INTERNET_OPEN_TYPE_PROXY = 3;
    const int INTERNET_OPEN_TYPE_DIRECT = 1;

    Struct_INTERNET_PROXY_INFO struct_IPI;

    // Filling in structure 
    if (strProxy==":")
    {
        struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_DIRECT;
    }
    else
    {
        struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
    }
    struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy);
    struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local");

    // Allocating memory 
    IntPtr intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI));

    // Converting structure to IntPtr 
    Marshal.StructureToPtr(struct_IPI, intptrStruct, true);

    bool iReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(struct_IPI));

}

Upvotes: 0

Boeckm
Boeckm

Reputation: 3312

Looks like this question was asked some time ago, but I just spent the last 2 hours researching this and couldn't find an answer. Finally I found some obscure site on accident with code that works.

Try your code above again, but instead of specifying the actual proxy address, use ":" instead.

Call RefreshIESettings like so: RefreshIESettings(":")

Upvotes: 0

Related Questions