分享

使用vbs添加windows网络代理

 精英部落 2022-02-19

添加代理脚本,把代码里面的Data="172.16.1.1:8120" 更改成自己的代理地址及端口,把需要排除不通过代理的对象修改成一下 Data="192.*;<local>;" ,把以下代理保存到文本文档,保存后,修改文本的扩展名为vbs即可

On error resume next

Const HKEY_CURRENT_USER = &H80000001  

Const HKEY_LOCAL_MACHINE = &H80000002  

Const HKEY_USERS = &H80000003  

Const HKEY_CURRENT_CONFIG = &H80000005  

Const HKEY_DYN_DATA = &H80000006  

Const REG_SZ = 1  

Const REG_EXPAND_SZ = 2  

Const REG_BINARY = 3  

Const REG_DWORD = 4  

Const REG_MULTI_SZ = 7

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"  

strValue = "SavedLegacySettings" 

Data=Array(&H46,&H00,&H00,&H00,&H87,&H0a,&H00,&H00,&H03,&H00,&H00,&H00,&H16,&H00,&H00,&H00,&H70,&H72,&H6f,&H78,&H79,&H2e,&H73,&H6f,&H6e,&H79,&H2e,&H63,&H6f,&H6d,&H2e,&H63,&H6e,&H3a,&H38,&H30,&H38,&H30,&H2f,&H00,&H00,&H00,&H34,&H33,&H2e,&H2a,&H3b,&H2a,&H73,&H65,&H68,&H2e,&H73,&H6f,&H6e,&H79,&H2e,&H63,&H6f,&H6d,&H2e,&H63,&H6e,&H2a,&H3b,&H2a,&H2e,&H69,&H6d,&H61,&H70,&H73,&H76,&H32,&H2e,&H73,&H6f,&H6e,&H79,&H2e,&H2a,&H3b,&H3c,&H6c,&H6f,&H63,&H61,&H6c,&H3e,&H00,&H00,&H00,&H00,&H01,&H00,&H00,&H00,&H19,&H00,&H00,&H00,&H68,&H74,&H74,&H70,&H3a,&H2f,&H2f,&H34,&H33,&H2e,&H36,&H38,&H2e,&H38,&H2e,&H35,&H2f,&H77,&H70,&H61,&H64,&H2e,&H64,&H61,&H74,&H00,&H36,&H5c,&H16,&H57,&H0b,&Hc6,&H01,&H01,&H00,&H00,&H00,&H2b,&H52,&H24,&H58,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00)

Call hexRegWrite(strKeyPath, strValue, Data)

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings\Connections"  

strValue = "DefaultConnectionSettings"  

Data=Array(&H46,&H00,&H00,&H00,&H8e,&H00,&H00,&H00,&H03,&H00,&H00,&H00,&H16,&H00,&H00,&H00,&H70,&H72,&H6f,&H78,&H79,&H2e,&H73,&H6f,&H6e,&H79,&H2e,&H63,&H6f,&H6d,&H2e,&H63,&H6e,&H3a,&H38,&H30,&H38,&H30,&H2f,&H00,&H00,&H00,&H34,&H33,&H2e,&H2a,&H3b,&H2a,&H73,&H65,&H68,&H2e,&H73,&H6f,&H6e,&H79,&H2e,&H63,&H6f,&H6d,&H2e,&H63,&H6e,&H2a,&H3b,&H2a,&H2e,&H69,&H6d,&H61,&H70,&H73,&H76,&H32,&H2e,&H73,&H6f,&H6e,&H79,&H2e,&H2a,&H3b,&H3c,&H6c,&H6f,&H63,&H61,&H6c,&H3e,&H00,&H00,&H00,&H00,&H01,&H00,&H00,&H00,&H19,&H00,&H00,&H00,&H68,&H74,&H74,&H70,&H3a,&H2f,&H2f,&H34,&H33,&H2e,&H36,&H38,&H2e,&H38,&H2e,&H35,&H2f,&H77,&H70,&H61,&H64,&H2e,&H64,&H61,&H74,&H00,&H36,&H5c,&H16,&H57,&H0b,&Hc6,&H01,&H01,&H00,&H00,&H00,&H2b,&H52,&H24,&H58,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00,&H00)

Call hexRegWrite(strKeyPath, strValue, Data)

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"  

strValue = "ProxyEnable"

Data=00000001

Call dwordRegWrite(strKeyPath, strValue, Data)

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"  

strValue = "ProxyServer"

Data="172.16.1.1:8120"

Call strRegWrite(strKeyPath, strValue, Data)

strKeyPath = "Software\Microsoft\Windows\CurrentVersion\Internet Settings"  

strValue = "ProxyOverride"

Data="192.*;<local>;"

Call strRegWrite(strKeyPath, strValue, Data)

'WScript.Echo "Modify Completely!"

Sub hexRegWrite(strKeyPath, strValue, Data)  

strComputer = "."  

Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")   

objRegistry.CreateKey HKEY_CR, strKeyPath  

retcode = objRegistry.SetBinaryValue(HKEY_CURRENT_USER, strKeyPath, strValue, Data)   

If (retcode = 0) And (Err.Number = 0) Then  

  'WScript.Echo "Binary value added successfully"  

Else  

  WScript.Echo "An error occurred. Return code: " & retcode  

End If  

End Sub

Sub dwordRegWrite(strKeyPath, strValue, Data)  

strComputer = "."  

Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")   

objRegistry.CreateKey HKEY_CR, strKeyPath  

retcode = objRegistry.SetDwordValue(HKEY_CURRENT_USER, strKeyPath, strValue, Data)   

If (retcode = 0) And (Err.Number = 0) Then  

  'WScript.Echo "Binary value added successfully"  

Else  

  WScript.Echo "An error occurred. Return code: " & retcode  

End If  

End Sub

Sub strRegWrite(strKeyPath, strValue, Data)  

strComputer = "."  

Set objRegistry = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")   

objRegistry.CreateKey HKEY_CR, strKeyPath  

retcode = objRegistry.SetStringValue(HKEY_CURRENT_USER, strKeyPath, strValue, Data)   

If (retcode = 0) And (Err.Number = 0) Then  

  'WScript.Echo "Binary value added successfully"  

Else  

  WScript.Echo "An error occurred. Return code: " & retcode  

End If  

End Sub

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多