Advertisement
aveyo

ChangeMAC.cmd

Mar 11th, 2015
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 KB | None | 0 0
  1. <!-- : Change MAC by AveYo v3.0
  2. @ECHO OFF &SETLOCAL ENABLEEXTENSIONS
  3. GOTO :_INIT
  4.  
  5. :_START
  6. CALL "%SSVAR%\cscript.exe" //nologo "%~f0?.wsf" //job:MAC
  7. EXIT /B
  8.  
  9. :_INIT
  10. CD /D "%~dp0"
  11. SET "SSVAR=%WINDIR%\SYSTEM32"
  12. IF DEFINED PROCESSOR_ARCHITEW6432 SET "SSVAR=%WINDIR%\Sysnative"
  13. MODE 80,2 &COLOR 70 &TITLE %~n0 by A^v^eY^o^ v2^.^0
  14. IF "%1"=="_SELF_ADMIN" SHIFT &SHIFT &GOTO :_START
  15. "%SSVAR%\REG.EXE" QUERY "HKEY_USERS\S-1-5-20\Environment" /v TEMP 2>NUL 1>&2 && GOTO :_START || echo Requesting admin rights, if it fails, R-click and 'Run As Administrator' &COLOR 0c
  16. CALL "%SSVAR%\cscript.exe" //nologo "%~f0?.wsf" //job:ADM "%~f0" &EXIT
  17. GOTO :eof
  18.  
  19. ----- embeded scripts method by DosTips user Liviu --->
  20. <package>
  21. <job id="ADM">
  22. <script language="VBScript">
  23. On Error Resume Next
  24. CreateObject("Shell.Application").ShellExecute WScript.Arguments(0), "_SELF_ADMIN " & WScript.Arguments(0), "", "runas", 1
  25. Err.Clear
  26. </script>
  27. </job>
  28. <job id="MAC">
  29. <script language="VBScript">
  30. On Error Resume Next
  31. const HKEY_LOCAL_MACHINE = &H80000002
  32. Dim aName,aMAC,aIndex,filterMAC
  33. Set aREG=GetObject("winmgmts:StdRegProv")
  34. aKey = "SYSTEM\CurrentControlSet\Control\Class\{4D36E972-E325-11CE-BFC1-08002BE10318}"
  35. aValue = "NetworkAddress"
  36. Set aWMI = GetObject ("winmgmts:") 'NetConnectionID='Ethernet'
  37. Set adapters = aWMI.ExecQuery("Select PhysicalAdapter,PNPDeviceID,ProductName,Index,NetEnabled from Win32_NetworkAdapter where PhysicalAdapter=True and (PNPDeviceID LIKE '%USB%' or PNPDeviceID LIKE '%PCI%')","WQL",48) '48=wbemFlagForwardOnly + wbemFlagReturnImmediately
  38. For Each adapter in adapters
  39. With adapter
  40. aName = .ProductName
  41. aIndex = "\" & Right("0000" & .Index, 4)
  42. aREG.GetStringValue HKEY_LOCAL_MACHINE,aKey & aIndex,aValue,aMAC
  43. If IsNull(aMAC) Then aMAC=""
  44. changeMAC=Trim(InputBox(aName & vbCrLf & vbCrLf & "Enter new MAC address: (any separator .,: works)" & vbCrLf & "or 0 to reset it", "ChangeMac by AveYo", aMAC))
  45. filterMAC=Split("._ _,_:_;_-_<_>_[_]_{_}_(_)","_")
  46. For each x in filterMAC
  47. changeMAC=Replace(changeMAC,x,"")
  48. WScript.Echo changeMAC
  49. Next
  50. If changeMAC <> aMAC And changeMAC <> "" Then
  51. If changeMAC="0" Then aREG.DeleteValue HKEY_LOCAL_MACHINE,aKey & aIndex,aValue Else aREG.SetStringValue HKEY_LOCAL_MACHINE,aKey & aIndex,aValue,changeMAC End If
  52. 'If (.NetEnabled) Then adapter.disable() Else adapter.enable()
  53. 'If Not (.NetEnabled) Then adapter.enable() Else adapter.disable()
  54. End If
  55. End With
  56. Next
  57. Err.Clear
  58. </script>
  59. </job>
  60. </package>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement