鱼C论坛

 找回密码
 立即注册
查看: 2046|回复: 0

[学习笔记] 尝试使用EXCEL 来完成MAC地址的修改工作

[复制链接]
发表于 2023-4-27 15:46:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-12-23 22:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表