On Error Resume Next strComputer = "." Set objWMIService = GetObject("winmgmts:\" & strComputer & "
ootcimv2") Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=true", , 48) For Each objItem in colItems msg = msg & "编号:" & objItem.Index & " MAC:" & objItem.MACAddress & vbCrLf & "网卡:" & objItem.Description & vbCrLf & vbCrLf Next
idx = InputBox( msg , "1/2请输入您要修改的MAC的编号", "1") If Not IsNumeric(idx) Or Len(idx) = 0 Then WScript.Echo "编号输入有误,退出" Wscript.Quit End If MAC = InputBox( "输入你指定的MAC地址值(注意应该是12位的连续数字或字母,其间没有-、:等分隔符)" , "2/2请输入修改后的MAC地址", "000000000000") MAC = Replace(Replace(Replace(MAC, ":", ""), "-", ""), " ", "") If RegExpTest("[^da-fA-F]", MAC)>0 Or Len(MAC)<>12 Then WScript.Echo "MAC输入有误,退出" Wscript.Quit End If
Function restartNetWork(sConnectionName) "重启网卡 "sConnectionName = "本地连接 5" "可改成需要控制的连接名称,如"无线网络连接"等 "定位到网络连接 Set shellApp = CreateObject("shell.application") Set oControlPanel = shellApp.Namespace(3) For Each folderitem in oControlPanel.Items If folderitem.Name = "网络连接" Then Set oNetConnections = folderitem.GetFolder Exit For End If Next "定位到要处理的网卡 For Each folderitem in oNetConnections.Items If LCase(folderitem.Name) = LCase(sConnectionName) Then Set oLanConnection = folderitem Exit For End If Next "重启网卡 For i = 1 To 2 For Each verb in oLanConnection.verbs If RegExpTest("启用|禁用|停止", verb.Name)>0 Then verb.DoIt Exit For End If Next "有时网卡半天反应不过来,可以把这个参数设的大点一般程序可以正常运行,或您多运行几次程序 WScript.Sleep 5000 Next
End Function
"正则测试有没有匹配内容
Function RegExpTest(patrn, strng) Set re = New RegExp re.Pattern = patrn re.IgnoreCase = True re.Global = True Set Matches = re.Execute(strng) RegExpTest = Matches.Count End Function 当前1/2页 12下一页