马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
Private Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal dwmilliseconds As Long)
Sub wp()
Set obj = GetObject("winmgmts:\\.\root\cimv2")
Set items = obj.execquery("select * from win32_networkadapterconfiguration where ipenabled=true", , 48)
i = 3
Range("i:i").Select
Range("h:h").Clear
Range("i:i").Clear
Selection.HorizontalAlignment = xlHAlignLeft
For Each Item In items
Range("h" & Trim(Str(i))).Value = "活动网卡序号"
Range("i" & Trim(Str(i))).Value = Item.Index
Range("h" & Trim(Str(i + 1))).Value = "活动网卡MAC地址"
Range("i" & Trim(Str(i + 1))).Value = Item.macaddress
Range("h" & Trim(Str(i + 2))).Value = "活动网卡名称"
Range("i" & Trim(Str(i + 2))).Value = Item.Description
i = i + 4
'Debug.Print Item.Index, Item.macaddress, Item.Description
Next
Range("h:h").EntireColumn.AutoFit
Range("i:i").EntireColumn.AutoFit
Range("h" & Trim(Str(i))).Value = "请在下面单元格填写当前电脑的主网卡序号"
Range("h" & Trim(Str(i + 1))).Value = Range("i3").Value
Range("h" & Trim(Str(i + 1))).Select
Selection.HorizontalAlignment = xlHAlignLeft
Selection.NumberFormatLocal = "0000"
End Sub
Sub rebootnet()
Set wsshell = CreateObject("wscript.shell")
reg = "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Class\{4d36e972-e325-11ce-bfc1-08002be10318}" & WorksheetFunction.Text(Range("h12"), "0000")
Debug.Print reg
networkname = wsshell.regread(reg & "\NetCfgInstanceId")
Debug.Print networkname
reg2 = wsshell.regread("HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\network\{4d36e972-e325-11ce-bfc1-08002be10318}" & networkname & "\connection\name")
Debug.Print reg2
wsshell.popup "程序将重启你的网卡,请稍后......", 2, "MAC修改", 64
wsshell.Run ("cmd /c netsh interface set interface " & reg2 & " disabled"), 0
Sleep 5000
Debug.Print "ok"
wsshell.Run ("cmd /c netsh interface set interface " & reg2 & " enabled"), 0
Sleep (5000)
Debug.Print "over"
End Sub
|