'/*=========================================================================
' * Intro 網(wǎng)上找了一圈,都不怎么好,有一個(gè)比較不錯(cuò)的,漢化作者漢化時(shí)加了個(gè)自己的介紹文件,這個(gè)文件比程序本身還大,感覺不爽,于是本人的VBS版MAC修改代碼便誕生了,在使用過程中如果出現(xiàn)不能上網(wǎng)的情況得返回一下網(wǎng)卡驅(qū)動(dòng)(有些機(jī)器比較特別),如果要返回以前的MAC可以:開始-->控制面板-->網(wǎng)絡(luò)連接-->點(diǎn)擊您的網(wǎng)卡(一般是"本地連接")-->點(diǎn)擊常規(guī)里的屬性-->配置..-->高級(jí)-->選中-->NetworkAddress-->右邊選擇"不存在"
' * FileName ChangeMAC.vbs
' * Author yongfa365
' * Version v3.0
' * WEB http://www.yongfa365.com
' * Email yongfa365[at]qq.com
' * MadeTime 2007-12-09 22:17:58
' * LastModify 2007-12-13 18:35:58
' *==========================================================================*/
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" strComputer "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration where IPEnabled=true", , 48)
For Each objItem in colItems
msg = msg "編號(hào):" objItem.Index " MAC:" objItem.MACAddress vbCrLf "網(wǎng)卡:" objItem.Description vbCrLf vbCrLf
Next
idx = InputBox( msg , "1/2請(qǐng)輸入您要修改的MAC的編號(hào)", "1")
If Not IsNumeric(idx) Or Len(idx) = 0 Then
WScript.Echo "編號(hào)輸入有誤,退出"
Wscript.Quit
End If
MAC = InputBox( "輸入你指定的MAC地址值(注意應(yīng)該是12位的連續(xù)數(shù)字或字母,其間沒有-、:等分隔符)" , "2/2請(qǐng)輸入修改后的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
idx = Right("00000"idx, 4)
reg = "HKLM\SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002bE10318}\" idx
Set WSHShell = CreateObject("WScript.Shell")
WshShell.RegWrite reg "\NetworkAddress", MAC , "REG_SZ"
WshShell.RegWrite reg "\Ndi\params\NetworkAddress\default" , MAC , "REG_SZ"
WshShell.RegWrite reg "\Ndi\params\NetworkAddress\ParamDesc" , "NetworkAddress" , "REG_SZ"
WshShell.RegWrite reg "\Ndi\params\NetworkAddress\optional" , "1" , "REG_SZ"
'得到網(wǎng)卡的名稱,比如“本地連接 2”
NetWorkName = WshShell.RegRead("HKLM\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\" WshShell.RegRead(reg "\NetCfgInstanceId") "\Connection\Name")
restartNetWork NetWorkName
'WScript.Echo "修改成功"
Function restartNetWork(sConnectionName)
'重啟網(wǎng)卡
'sConnectionName = "本地連接 5" '可改成需要控制的連接名稱,如"無線網(wǎng)絡(luò)連接"等
'定位到網(wǎng)絡(luò)連接
Set shellApp = CreateObject("shell.application")
Set oControlPanel = shellApp.Namespace(3)
For Each folderitem in oControlPanel.Items
If folderitem.Name = "網(wǎng)絡(luò)連接" Then
Set oNetConnections = folderitem.GetFolder
Exit For
End If
Next
'定位到要處理的網(wǎng)卡
For Each folderitem in oNetConnections.Items
If LCase(folderitem.Name) = LCase(sConnectionName) Then
Set oLanConnection = folderitem
Exit For
End If
Next
'重啟網(wǎng)卡
For i = 1 To 2
For Each verb in oLanConnection.verbs
If RegExpTest("啟用|禁用|停止", verb.Name)>0 Then
verb.DoIt
Exit For
End If
Next
'有時(shí)網(wǎng)卡半天反應(yīng)不過來,可以把這個(gè)參數(shù)設(shè)的大點(diǎn)一般程序可以正常運(yùn)行,或您多運(yùn)行幾次程序
WScript.Sleep 5000
Next
End Function
'正則測(cè)試有沒有匹配內(nèi)容
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