发现这个跨度还是挺打的,开始写一些脚本和C# Console工具
这边文章主要讲怎样修改网卡的参数,手动修改可以通过点击“网卡”--“属性”--网卡的“配置”--“高级”
对应到程序中,这些参数就对应到相应的注册表项
configurationNetwordAdapter
Sub configurationNetwordAdapter( NetworkAdapterName )
Dim strKeyPathConnection,strComputer,objRegistry,Subkey
Dim NetCfgId,strKeyPath,arrSubKeys,strValueName,strValue
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each Subkey In arrSubKeys
strKeyPathConnection=strKeyPath & "\" & Subkey & "\Connection"
strValueName = "Name"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPathConnection,strValueName,strValue
If IsNull(strValue) Then
Else
If (strValue=NetworkAdapterName) Then
NetCfgId=Subkey
Wscript.Echo "find the NetworkAdapter " & NetworkAdapterName
End If
End If
Next
If IsEmpty(NetCfgId) Then
Wscript.Echo "Not Find the networkAdapter " & NetworkAdapterName
Exit Sub
End If
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
strKeyPathConnection=strKeyPath
For Each Subkey In arrSubKeys
strKeyPathConnection=strKeyPath & "\" & Subkey
strValueName = "NetCfgInstanceId"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPathConnection,strValueName,strValue
If IsNull(strValue) Then
Else
If (strValue=NetCfgId) Then
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPathConnection, "*IPChecksumOffloadIPv4", "0"
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPathConnection, "*LsoV2IPv4", "0"
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPathConnection, "*RSS", "0"
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPathConnection, "*LsoV2IPv6", "0"
Wscript.Echo "Setting Success."
End If
End If
Next
End Sub
针对这段代码,根据传入的网卡名称,获取相应网卡的GUID,然后找到相应设置并修改
Sub configurationNetwordAdapter( NetworkAdapterName )
Dim strKeyPathConnection,strComputer,objRegistry,Subkey
Dim NetCfgId,strKeyPath,arrSubKeys,strValueName,strValue
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & _
strComputer & "\root\default:StdRegProv")
strKeyPath = "SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
For Each Subkey In arrSubKeys
strKeyPathConnection=strKeyPath & "\" & Subkey & "\Connection"
strValueName = "Name"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPathConnection,strValueName,strValue
If IsNull(strValue) Then
Else
If (strValue=NetworkAdapterName) Then
NetCfgId=Subkey
Wscript.Echo "find the NetworkAdapter " & NetworkAdapterName
End If
End If
Next
If IsEmpty(NetCfgId) Then
Wscript.Echo "Not Find the networkAdapter " & NetworkAdapterName
Exit Sub
End If
strKeyPath = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"
objRegistry.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys
strKeyPathConnection=strKeyPath
For Each Subkey In arrSubKeys
strKeyPathConnection=strKeyPath & "\" & Subkey
strValueName = "NetCfgInstanceId"
objRegistry.GetStringValue HKEY_LOCAL_MACHINE,strKeyPathConnection,strValueName,strValue
If IsNull(strValue) Then
Else
If (strValue=NetCfgId) Then
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPathConnection, "*IPChecksumOffloadIPv4", "0"
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPathConnection, "*LsoV2IPv4", "0"
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPathConnection, "*RSS", "0"
objRegistry.SetStringValue HKEY_LOCAL_MACHINE, strKeyPathConnection, "*LsoV2IPv6", "0"
Wscript.Echo "Setting Success."
End If
End If
Next
End Sub
根据这个路径网卡对应的GUID:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}
使用上面找到的ID,进入这个位置HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}寻找对应的 NetCfgInstanceId,然后修改对应的值。