Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for macos2.cmd

(view source code of macos2.cmd as plain text)

  1. @ECHO OFF
  2. REM MacOS2.cmd,  Version 2.10
  3. REM Finds the network adapter's MacAddress
  4. REM and stores it in an environment variable
  5. REM Written by Rob van der Woude
  6.  
  7. REM Initializing
  8. SET MACTMPBT=
  9. SET MACTMPDR=
  10. SET SERVICE=
  11.  
  12. REM Add %TEMP% to PATH, assuming everyone has write access in %TEMP%
  13. IF "%TEMP%"=="" GOTO NoTemp
  14. SET MACTMPDR=%TEMP%.\
  15. SET OLDPATH=%PATH%
  16. PATH %TEMP%;%PATH%
  17. :NoTemp
  18.  
  19. REM Use DATE to parse NET CONFIG services output
  20. NET CONFIG | FIND /V ":" | FIND /V "." | DATE > %MACTMPDR%MACTEMP.DAT
  21.  
  22. REM Check which language is used, to enable use of DATE in parsing
  23. REM English?
  24. TYPE %MACTMPDR%MACTEMP.DAT | CUT -F:1 -L:1 | FIND "Enter" > NUL
  25. IF NOT ERRORLEVEL 1 SET MACTMPBT=ENTER
  26. IF NOT ERRORLEVEL 1 SET ACTIVE=active
  27. REM Or Dutch?
  28. TYPE %MACTMPDR%MACTEMP.DAT | CUT -F:1 -L:1 | FIND "Voer" > NUL
  29. IF NOT ERRORLEVEL 1 SET MACTMPBT=VOER
  30. IF NOT ERRORLEVEL 1 SET ACTIVE=actief
  31.  
  32. REM Language doesn't seem to be implemented yet
  33. IF "%MACTMPBT%"=="" GOTO UnknownLanguage
  34.  
  35. REM Continue filtering temporary file and create temporary batch file
  36. TYPE %MACTMPDR%MACTEMP.DAT | FIND "):" > %MACTMPDR%MACTEMP.CMD
  37. IF ERRORLEVEL 1 TYPE %MACTMPDR%MACTEMP.DAT | FIND ": (" > %MACTMPDR%MACTEMP.CMD
  38.  
  39. REM Create language dependent temporary batch file
  40. ECHO IF "%%SERVICE%%"=="" SET SERVICE=%%6>  %MACTMPDR%%MACTMPBT%.CMD
  41. ECHO IF "%%SERVICE%%"=="" SET SERVICE=%%5>> %MACTMPDR%%MACTMPBT%.CMD
  42.  
  43. REM Execute temporary batch files
  44. CALL %MACTMPDR%MACTEMP.CMD
  45.  
  46. REM Check correct execution of temporary batch files
  47. IF "%SERVICE%"=="" GOTO UnknownLanguage
  48.  
  49. REM Use NET CONFIG with found service to get MacAddress
  50. REM Due to the limited number of nested pipes allowed,
  51. REM we have to split the filtering and use temporary files
  52. NET CONFIG %SERVICE% | FIND " %ACTIVE% " | CUT -F:2 -L:1 -D:"(" | CUT -F:1 -L:1 -D:")" > %MACTMPDR%MACTEMP.DAT
  53.  
  54. REM Reset variable to enable reuse
  55. SET SERVICE=
  56.  
  57. REM Due to the limited number of nested pipes allowed,
  58. REM we have to split the filtering and use temporary files
  59. TYPE %MACTMPDR%MACTEMP.DAT | DATE | FIND /I "%MACTMPBT%" > %MACTMPDR%MACTEMP.CMD
  60. CALL %MACTMPDR%MACTEMP.CMD
  61.  
  62. REM Check correct execution of temporary batch files
  63. IF "%SERVICE%"=="" GOTO UnknownLanguage
  64.  
  65. REM Save results
  66. SET MacAddr=%SERVICE%
  67. ECHO.
  68. ECHO MacAddress=%MacAddr%
  69. GOTO End
  70.  
  71. :UnknownLanguage
  72. ECHO Error, probably unknown OS language
  73. ECHO Known languages so far: English and Dutch
  74. GOTO End
  75.  
  76. :ResetPath
  77. REM Remove %TEMP% from PATH again
  78. PATH %OLDPATH%
  79. SET OLDPATH=
  80.  
  81. :End
  82. REM Clean up temporary files and variables
  83. IF NOT "%OLDPATH%"=="" GOTO ResetPath
  84. IF EXIST %MACTMPDR%MACTEMP.* DEL %MACTMPDR%MACTEMP.*
  85. IF EXIST %MACTMPDR%%MACTMPBT%.CMD DEL %MACTMPDR%%MACTMPBT%.CMD
  86. SET ACTIVE=
  87. SET MACTMPBT=
  88. SET MACTMPDR=
  89. SET SERVICE=
  90.  

page last uploaded: 2017-08-21, 14:26