如何使用VBScript配置网卡参数

最近刚刚换了工作,从做asp.net的网页开发,到了做微软Vendors 的SDET
发现这个跨度还是挺打的,开始写一些脚本和C# Console工具
这边文章主要讲怎样修改网卡的参数,手动修改可以通过点击“网卡”--“属性”--网卡的“配置”--“高级”
对应到程序中,这些参数就对应到相应的注册表项
ContractedBlock.gif ExpandedBlockStart.gif 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,然后找到相应设置并修改
根据这个路径网卡对应的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,然后修改对应的值。

转载于:https://www.cnblogs.com/billmo/archive/2009/09/26/1574467.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值