Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for getports.bat

(view source code of getports.bat as plain text)

  1. @ECHO OFF
  2. REM * GetPorts, Version 2.12 for all DOS flavours
  3. REM * Written by Rob van der Woude, http://www.xs4all.nl/~robw/rob/index.html
  4. REM * Needs DEBUG and CHOICE.COM
  5.  
  6.  
  7. REM * "Initialize" variables used
  8. FOR %%A IN (1 2 3 4) DO SET COM%%A=
  9. FOR %%A IN (1 2 3) DO SET LPT%%A=
  10.  
  11. REM * Create DEBUG script and use it to read port addresses
  12. REM * (information provided by Alfred Poor in PC Magazine)
  13. ECHO D 40:0 L E> GETPORTS.SCR
  14. ECHO Q>> GETPORTS.SCR
  15. DEBUG < GETPORTS.SCR | FIND "40:0" | FIND /V "-D " > GETPORTS.DAT
  16.  
  17. REM * All code following is used to parse the string
  18. REM * that DEBUG returned into readable information
  19.  
  20. REM * NT only
  21. VER | FIND "Windows NT" > NUL
  22. IF ERRORLEVEL 1 GOTO DOS
  23. FOR /F "TOKENS=2-16* DELIMS=- " %%A IN (GETPORTS.DAT) DO (
  24. 	SET COM1=%%B%%A
  25. 	SET COM2=%%D%%C
  26. 	SET COM3=%%F%%E
  27. 	SET COM4=%%H%%G
  28. 	SET LPT1=%%J%%I
  29. 	SET LPT2=%%L%%K
  30. 	SET LPT3=%%N%%M
  31. )
  32. GOTO DisplayAll
  33.  
  34. :DOS
  35. REM * Use DATE to store the string in several variables, as
  36. REM * explained in http://www.xs4all.nl/~robw/rob/datetime.html
  37. ECHO.>> GETPORTS.DAT
  38. TYPE GETPORTS.DAT | DATE | FIND "40:0" > GETPORT$.BAT
  39.  
  40. REM * Different DOS versions and languages
  41. REM * need different temporary batch files
  42. VER | DATE | FIND /I "VOER" > NUL
  43. IF NOT ERRORLEVEL 1 SET ENTER=VOER
  44. VER | DATE | FIND /I "TYP" > NUL
  45. IF NOT ERRORLEVEL 1 SET ENTER=TYP
  46. VER | DATE | FIND /I "CURRENT" > NUL
  47. IF NOT ERRORLEVEL 1 SET ENTER=ENTER
  48. GOTO Make%ENTER%
  49.  
  50. :MakeENTER
  51. REM * English DOS version
  52. ECHO @ECHO OFF> %ENTER%.BAT
  53. ECHO IF "%%1"=="Loop2" GOTO Loop2>> %ENTER%.BAT
  54. ECHO FOR %%%%A IN (1 2 3 4 5) DO SHIFT>> %ENTER%.BAT
  55. GOTO MakeAll
  56.  
  57. :MakeTYP
  58. REM * Dutch Win98 version
  59. ECHO @ECHO OFF> %ENTER%.BAT
  60. ECHO IF "%%1"=="Loop2" GOTO Loop2>> %ENTER%.BAT
  61. ECHO FOR %%%%A IN (1 2 3 4) DO SHIFT>> %ENTER%.BAT
  62. GOTO MakeAll
  63.  
  64. :MakeVOER
  65. REM * Dutch DOS version
  66. ECHO @ECHO OFF> %ENTER%.BAT
  67. ECHO IF "%%1"=="Loop2" GOTO Loop2>> %ENTER%.BAT
  68. ECHO FOR %%%%A IN (1 2 3 4 5 6) DO SHIFT>> %ENTER%.BAT
  69. GOTO MakeAll
  70.  
  71. :MakeAll
  72. REM * Common to all DOS versions
  73. ECHO SET COM1=%%2%%1>> %ENTER%.BAT
  74. ECHO SET COM2=%%4%%3>> %ENTER%.BAT
  75. ECHO SET COM3=%%6%%5>> %ENTER%.BAT
  76. ECHO SET COM4=%%7>> %ENTER%.BAT
  77.  
  78. REM * Get rid of the hyphen connecting two
  79. REM * parameters, using Outsider's CHOICE trick
  80. ECHO SET Loop2=>> %ENTER%.BAT
  81. ECHO EXIT|%COMSPEC%/KPROMPT $_ECHO ]$BCHOICE/C:[;%%8;] %ENTER%.BAT Loop2 ;$G%ENTER%$$.BAT$_|FIND "Loop2">>%ENTER%.BAT
  82.  
  83. ECHO CALL %ENTER%$.BAT>> %ENTER%.BAT
  84. ECHO FOR %%%%A IN (1 2 3 4 5 6 7) DO SHIFT>> %ENTER%.BAT
  85. ECHO SET LPT1=%%2%%Loop2%%>> %ENTER%.BAT
  86. ECHO SET LPT2=%%4%%3>> %ENTER%.BAT
  87. ECHO SET LPT3=%%6%%5>> %ENTER%.BAT
  88. ECHO GOTO End>> %ENTER%.BAT
  89.  
  90. REM * Part two of Outsider's CHOICE trick
  91. ECHO :Loop2>> %ENTER%.BAT
  92. ECHO IF "%%2"=="-" SET COM4=%%Loop2%%%%COM4%%>> %ENTER%.BAT
  93. ECHO IF "%%2"=="-" SET Loop2=>> %ENTER%.BAT
  94. ECHO IF "%%2"=="0" SET Loop2=%%Loop2%%0>> %ENTER%.BAT
  95. ECHO IF "%%2"=="1" SET Loop2=%%Loop2%%1>> %ENTER%.BAT
  96. ECHO IF "%%2"=="2" SET Loop2=%%Loop2%%2>> %ENTER%.BAT
  97. ECHO IF "%%2"=="3" SET Loop2=%%Loop2%%3>> %ENTER%.BAT
  98. ECHO IF "%%2"=="4" SET Loop2=%%Loop2%%4>> %ENTER%.BAT
  99. ECHO IF "%%2"=="5" SET Loop2=%%Loop2%%5>> %ENTER%.BAT
  100. ECHO IF "%%2"=="6" SET Loop2=%%Loop2%%6>> %ENTER%.BAT
  101. ECHO IF "%%2"=="7" SET Loop2=%%Loop2%%7>> %ENTER%.BAT
  102. ECHO IF "%%2"=="8" SET Loop2=%%Loop2%%8>> %ENTER%.BAT
  103. ECHO IF "%%2"=="9" SET Loop2=%%Loop2%%9>> %ENTER%.BAT
  104. ECHO IF "%%2"=="A" SET Loop2=%%Loop2%%A>> %ENTER%.BAT
  105. ECHO IF "%%2"=="B" SET Loop2=%%Loop2%%B>> %ENTER%.BAT
  106. ECHO IF "%%2"=="C" SET Loop2=%%Loop2%%C>> %ENTER%.BAT
  107. ECHO IF "%%2"=="D" SET Loop2=%%Loop2%%D>> %ENTER%.BAT
  108. ECHO IF "%%2"=="E" SET Loop2=%%Loop2%%E>> %ENTER%.BAT
  109. ECHO IF "%%2"=="F" SET Loop2=%%Loop2%%F>> %ENTER%.BAT
  110. ECHO SHIFT>> %ENTER%.BAT
  111. ECHO IF NOT "%%2"=="" GOTO Loop2>> %ENTER%.BAT
  112. ECHO :End>> %ENTER%.BAT
  113.  
  114. REM * Finally, let's USE all those batch files we just created
  115. CALL GETPORT$.BAT
  116.  
  117. :DisplayAll
  118. REM * Display the results (no FOR loop possible because of Win98)
  119. ECHO.
  120. ECHO COM1=%COM1%
  121. ECHO COM2=%COM2%
  122. ECHO COM3=%COM3%
  123. ECHO COM4=%COM4%
  124. ECHO LPT1=%LPT1%
  125. ECHO LPT2=%LPT2%
  126. ECHO LPT3=%LPT3%
  127. ECHO.
  128.  
  129. REM * Clean up the mess
  130. FOR %%A IN (%ENTER% %ENTER%$ GETPORT$) DO IF EXIST %%A.BAT DEL %%A.BAT
  131. FOR %%A IN (DAT SCR) DO IF EXIST GETPORTS.%%A DEL GETPORTS.%%A
  132. SET Loop2=
  133.  
  134. :End
  135.  

page last modified: 2024-04-16; loaded in 0.0083 seconds