vbs Windows系統改變或修改網卡的MAC地址的指令碼與軟體第1/2頁

來源:互聯網
上載者:User

'/*=========================================================================
' * Intro 網上找了一圈,都不怎麼好,有一個比較不錯的,漢化作者漢化時加了個自己的介紹檔案,這個檔案比程式本身還大,感覺不爽,於是本人的VBS版MAC修改代碼便誕生了,在使用過程中如果出現不能上網的情況得返回一下網卡驅動(有些機器比較特別),如果要返回以前的MAC可以:開始-->控制台-->網路連接-->點擊您的網卡(一般是"本地串連")-->點擊常規裡的屬性-->配置..-->進階-->選中-->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 & "編號:" & 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

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"
'得到網卡的名稱,比如“本地串連 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)
'重啟網卡
'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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.