[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
脚本保存为 a.vbs
  1. Option Explicit
  2. On Error Resume Next
  3. Const conINI = "D:\mis.ini" 'ini路径
  4. Const conNIC = "vEthernet (Default Switch)" '网卡名
  5. Const ForReading = 1, ForWriting = 2, ForAppending = 8
  6. Dim objWbemServices,fso,tsr,tsw,Element,dicNIC_ININO,mac,str
  7. Set dicNIC_ININO = CreateObject("Scripting.Dictionary")
  8. ' MAC地址对应COUNTER_NO
  9. dicNIC_ININO.Add "00:15:5D:62:F7:80","12863768"
  10. dicNIC_ININO.Add "00:15:5D:62:F7:90","12863767"
  11. dicNIC_ININO.Add "00:15:5D:62:F7:72","12863765"
  12. dicNIC_ININO.Add "00:15:5D:62:F7:42","12863764"
  13. dicNIC_ININO.Add "00:15:5D:62:F7:32","12863763"
  14. dicNIC_ININO.Add "00:15:5D:62:F7:02","12863762"
  15. dicNIC_ININO.Add "00:15:5D:62:F7:12","12863761"
  16. dicNIC_ININO.Add "00:15:5D:62:F7:96","12863759"
  17. dicNIC_ININO.Add "00:15:5D:62:F7:98","12863758"
  18. dicNIC_ININO.Add "00:15:5D:62:F7:66","12863757"
  19. Set fso = CreateObject("Scripting.FileSystemObject")
  20. Set objWbemServices = GetObject("winmgmts:{ImpersonationLevel=Impersonate}!//./root/cimv2")
  21. For Each Element In objWbemServices.ExecQuery("Select NetConnectionID,MACAddress From Win32_NetworkAdapter Where NetConnectionID = '" & conNIC & "'")
  22.   mac = Element.MACAddress
  23. Next
  24. ' WScript.Echo "mac='" & mac & "'"
  25. If dicNIC_ININO.Exists(mac) Then
  26.   Set tsr = fso.OpenTextFile(conINI,ForReading,False,vbUseDefault) ' ANSI encoding
  27.   str = tsr.ReadAll
  28.   If Err.Number <> 0 Then MyQuit
  29.   Set tsw = fso.OpenTextFile(conINI,ForWriting,False,vbUseDefault) ' ANSI encoding
  30.   If Err.Number <> 0 Then MyQuit
  31.   With New RegExp
  32.     .Global = False
  33.     .Ignorecase = True
  34.     .Multiline = False
  35.     .Pattern = "(COUNTER_NO\s*=\s*).*"
  36.     tsw.Write(.Replace(str,"$1" & dicNIC_ININO.Item(mac)))
  37.   End With
  38. End If
  39. MyQuit
  40. Sub MyQuit()
  41.   On Error Resume Next
  42.   If IsObject(tsw) Then
  43.     tsw.Close
  44.     Set tsw = Nothing
  45.   End If
  46.   If IsObject(tsr) Then
  47.     tsr.Close
  48.     Set tsr = Nothing
  49.   End If
  50.   Set fso = Nothing
  51.   set dicNIC_ININO = Nothing
  52.   Set objWbemServices = Nothing
  53.   WScript.Quit
  54. End Sub
复制代码
微信:flashercs
QQ:49908356

TOP

回复 13# jld95810


    把你改后的内容贴出来。MAC地址要大写
微信:flashercs
QQ:49908356

TOP

回复 17# jld95810

请修改ini路径,网卡名和MAC地址;否则脚本无效。
微信:flashercs
QQ:49908356

TOP

返回列表