Use WMI change ie proxy

Time:2020-5-8

Save the following code as vbs

Copy codeThe code is as follows:
If WScript.Arguments.Count = 0 Then
GetI = -1
Else
GetI = CInt(WScript.Arguments(0))
End If

Call YourCode()

‘write all the agents you get in a text file (IP. Txt), one line at a time: IP: Port
IPS = CreateObject(“Scripting.FileSystemObject”).OpenTextFile(“IP.txt”, 1, True).ReadAll
IPS = Split(IPS, vbCrLf)

For IPS_I = 0 To UBound(IPS)
If IPS_I > GetI Then
IPTemp = Split(IPS(IPS_I), “:”)
ChangeProxy IPTemp(0), IPTemp(1)
Set WshShell = CreateObject(“wscript.shell”)
WshShell.run(“cscript ” & WScript.ScriptFullName & ” ” & IPS_I)
wscript.quit
End If
Next

Sub YourCode()
‘your code
End Sub

‘use WMI change ie proxy

Function ChangeProxy(IP, Port)
‘get computer name
‘Set oNetwork = WScript.CreateObject(“WScript.Network”)
‘computername=oNetwork.ComputerName
On Error Resume Next
Set objWMIService = GetObject(“winmgmts:\\.\root\CIMV2”)
Set objShare = objWMIService.Get(“Win32_Proxy.ServerName=’computername'”)
Set objInParam = objShare.Methods_(“SetProxySetting”).inParameters.SpawnInstance_()
objInParam.Properties_.Item(“ProxyPortNumber”) = Port
objInParam.Properties_.Item(“ProxyServer”) = IP
Set objOutParams = objWMIService.ExecMethod(“Win32_Proxy.ServerName=’computername'”, “SetProxySetting”, objInParam)
End Function