Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在firefox VB.net中以编程方式更改代理_Vb.net_Google Chrome_Firefox_Proxy - Fatal编程技术网

在firefox VB.net中以编程方式更改代理

在firefox VB.net中以编程方式更改代理,vb.net,google-chrome,firefox,proxy,Vb.net,Google Chrome,Firefox,Proxy,我得到了一段可以在webbrowser中设置代理(ip:port)的代码,有没有办法通过VB.net编程在Firefox或Chrome中设置代理 <Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _ Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, By

我得到了一段可以在webbrowser中设置代理(ip:port)的代码,有没有办法通过VB.net编程在Firefox或Chrome中设置代理

<Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _
Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
End Function

Public Structure Struct_INTERNET_PROXY_INFO
    Public dwAccessType As Integer
    Public proxy As IntPtr
    Public proxyBypass As IntPtr
End Structure

Private Sub RefreshIESettings(ByVal strProxy As String)
    Const INTERNET_OPTION_PROXY As Integer = 38
    Const INTERNET_OPEN_TYPE_PROXY As Integer = 3

    Dim struct_IPI As Struct_INTERNET_PROXY_INFO

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

    ' Allocating memory
    Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))

    ' Converting structure to IntPtr
    Marshal.StructureToPtr(struct_IPI, intptrStruct, True)

    Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
End Sub
_
私有共享函数InternetSetOption(ByVal hInternet作为IntPtr,ByVal dwOption作为Integer,ByVal lpBuffer作为IntPtr,ByVal lpdwBufferLength作为Integer)作为布尔值
端函数
公共结构结构结构互联网代理信息
作为整数的公共dwAccessType
作为IntPtr的公共代理
作为IntPtr的公共代理旁路
端部结构
私有子刷新设置(ByVal strProxy作为字符串)
常量INTERNET\u选项\u代理为整数=38
Const INTERNET\u OPEN\u TYPE\u代理为整数=3
Dim结构IPI作为结构INTERNET代理信息
"填充结构",
struct_IPI.dwAccessType=INTERNET_OPEN_TYPE_PROXY
struct_IPI.proxy=Marshal.StringToHGlobalAnsi(strProxy)
struct_IPI.proxyBypass=Marshal.StringToHGlobalAnsi(“本地”)
'分配内存
Dim INTPTRSSTRUCT As IntPtr=Marshal.allocTaskMem(Marshal.SizeOf(struct_IPI))
'将结构转换为IntPtr
Marshal.StructureToPtr(struct_IPI,intptrStruct,True)
Dim iReturn As Boolean=InternetSetOption(IntPtr.Zero、INTERNET\u OPTION\u PROXY、intptrStruct、System.Runtime.InteropServices.Marshal.SizeOf(struct\u IPI))
端接头

对于Firefox:您可以将设置添加到文件“prefs.js”中,该文件位于:

C:\Users\UserName\AppData\Roaming\Mozilla\Firefox\Profiles\??。默认值

只需在文件末尾添加以下行:

user_pref("network.proxy.ftp", "localhost");
user_pref("network.proxy.ftp_port", 10);
user_pref("network.proxy.http", "localhost");
user_pref("network.proxy.http_port", 10);
user_pref("network.proxy.socks", "localhost");
user_pref("network.proxy.socks_port", 10);
user_pref("network.proxy.ssl", "localhost");
user_pref("network.proxy.ssl_port", 10);
user_pref("network.proxy.type", localhost);

是的,就是这样,谢谢。但是如何在vb.net中找到prefs.js,路径似乎是dynamicEnvironment.GetEnvironmentVariable(“APPDATA”)和“Mozilla\Firefox\Profiles”对于路径的第一部分,正确的文件夹是最后没有“-”的文件夹!