共享手动获取的源码;~ $ConnectionName = 连接名
;~ $SetIPAddress =IP地址
;~ $SetSubnetmask = 子网掩码
;~ $SetGateway = 网关
;~ Dim $SetDns[2]
;~ $SetDns[0] = DNS1
;~ $SetDns[1] = DNS2
$objWMIService = ObjGet("winmgmts:\" & $strComputer & "\root\CIMV2")
$colItemName = $objWMIService.ExecQuery("SELECT * FROM Win32_NetworkAdapter Where NetConnectionID='" & $ConnectionName & "'", "WQL", 0x30)
For $objName In $colItemName
If $objName.NetConnectionID = $ConnectionName Then
$CardIndex=$objName.Index
ExitLoop
EndIf
Next
If $CardIndex =-1 Then
MsgBox(0,"错误",'找不到连接' )
Else
$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = TRUE And Index='" & $CardIndex & "'" , "WQL", _
$wbemFlagReturnImmediately + $wbemFlagForwardOnly)
If IsObj($colItems) Then
For $objNetAdapter In $colItems
$objNetAdapter.EnableStatic ($SetIPAddress, $SetSubnetmask)
$objNetAdapter.SetGateways ($SetGateway)
$objNetAdapter.SetDNSServerSearchOrder ($SetDns)
Next
EndIf
Endif
ji记得Global $wbemFlagReturnImmediately = 0x10, _ ;不要修改
$wbemFlagForwardOnly = 0x20 ;不要修改
|