Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for dispedid.bat

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

  1. @ECHO OFF
  2. :: Check Windows version
  3. IF NOT "%OS%"=="Windows_NT" GOTO Syntax
  4.  
  5. :: Switch to local environment
  6. SETLOCAL ENABLEDELAYEDEXPANSION
  7.  
  8. :: Check command line arguments (none required)
  9. IF NOT "%~1"=="" GOTO Syntax
  10.  
  11. :: Export a list of all monitors from the registry
  12. START /WAIT REGEDIT.EXE /E "%Temp%\dispedid0.dat" "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\DISPLAY"
  13.  
  14. :: Convert it from Unicode to ASCII
  15. TYPE "%Temp%\dispedid0.dat" > "%Temp%\dispedid0.txt"
  16.  
  17. :: Loop through the list of all monitors to find the "real" ones
  18. FOR /F "tokens=1 delims=[]" %%A IN ('TYPE "%Temp%\dispedid0.txt" ^| FINDSTR.EXE /R /B /I /C:"\[HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\DISPLAY\\[^\\]*\]" ^| FIND.EXE /I /V "Default"') DO CALL :Display1 "%%~A"
  19.  
  20. :: Display the results
  21. ECHO.
  22. ECHO Monitor EDID asset information
  23. ECHO.
  24. ECHO Manufacturer  : %Manufacturer%
  25. ECHO Description   : %DeviceDescr%
  26. ECHO Model         : %Model%
  27. ECHO Serial number : %Serial%
  28. ECHO.
  29.  
  30. :: Clean up the pile of temporary files
  31. FOR /L %%A IN (0,1,3) DO (
  32. 	IF EXIST "%Temp%\dispedid%%A.dat" DEL "%Temp%\dispedid%%A.dat"
  33. 	IF EXIST "%Temp%\dispedid%%A.txt" DEL "%Temp%\dispedid%%A.txt"
  34. )
  35.  
  36. :: Done
  37. ENDLOCAL
  38. GOTO:EOF
  39.  
  40.  
  41. :: == :: == :: == ::   S U B R O U T I N E S   :: == :: == :: == ::
  42.  
  43.  
  44. :Display1
  45. :: Export a list of monitor details from the registry
  46. START /WAIT REGEDIT.EXE /E "%Temp%\dispedid1.dat" %1
  47. :: Convert it from Unicode to ASCII
  48. TYPE "%Temp%\dispedid1.dat" > "%Temp%\dispedid1.txt"
  49. :: Escape the backslashes in the path search string
  50. SET Key=%1
  51. SET Key=%Key:\=\\%
  52. :: Call the next subroutine to export a smaller, more relevant part of the list (one level deeper)
  53. FOR /F "tokens=1 delims=[]" %%B IN ('TYPE "%Temp%\dispedid1.txt" ^| FINDSTR.EXE /R /B /I /C:"\[%Key:"=%\\[^\\]*\]"') DO CALL :Display2 "%%~B"
  54. GOTO:EOF
  55.  
  56.  
  57. :Display2
  58. :: Export a list of monitor details from the registry
  59. START /WAIT REGEDIT.EXE /E "%Temp%\dispedid2.dat" %1
  60. :: Convert it from Unicode to ASCII
  61. TYPE "%Temp%\dispedid2.dat" > "%Temp%\dispedid2.txt"
  62. :: Skip Windows' default plug and play monitors
  63. TYPE "%Temp%\dispedid2.txt" | FINDSTR.EXE /R /B /I /C:".Mfg.=.(" >NUL && GOTO:EOF
  64. TYPE "%Temp%\dispedid2.txt" | FINDSTR.EXE /R /B /I /C:".DeviceDesc.=.Plug and Play Monitor." >NUL && GOTO:EOF
  65. :: Extract the manufacturer name and device description
  66. FOR /F "tokens=2 delims==" %%C IN ('TYPE "%Temp%\dispedid2.txt" ^| FINDSTR.EXE /R /B /I /C:".Mfg.="') DO SET Manufacturer=%%~C
  67. FOR /F "tokens=2 delims==" %%C IN ('TYPE "%Temp%\dispedid2.txt" ^| FINDSTR.EXE /R /B /I /C:".DeviceDesc.="') DO SET DeviceDescr=%%~C
  68. :: Escape the backslashes in the path search string
  69. SET SubKey=%1
  70. SET SubKey=%SubKey:\=\\%
  71. :: Call the next subroutine to export only the EDID data
  72. FOR /F "tokens=1 delims=[]" %%C IN ('TYPE "%Temp%\dispedid2.txt" ^| FINDSTR.EXE /R /B /I /C:"\[%SubKey:"=%\\Device Parameters\]"') DO CALL :Display3 "%%~C"
  73. GOTO:EOF
  74.  
  75.  
  76. :Display3
  77. :: Export the raw EDID data from the registry
  78. START /WAIT REGEDIT.EXE /E "%Temp%\dispedid3.dat" %1
  79. :: Convert it from Unicode to ASCII
  80. TYPE "%Temp%\dispedid3.dat" > "%Temp%\dispedid3.txt"
  81. :: Read the raw EDID data from the temporary file and store it in a variable named EDID
  82. SET EDID=
  83. FOR /F "skip=3 tokens=1 delims=\ " %%D IN (%Temp%\dispedid3.txt) DO SET EDID=!EDID!%%D
  84. :: Trim the string to contain only the raw data
  85. FOR /F "tokens=2 delims=:" %%D IN ("%EDID%") DO SET EDID=%%D
  86. :: Call the next subroutine to find the model and serial
  87. :: number and convert these from hexadecimal to ASCII
  88. CALL :ParseEDID %EDID%
  89. GOTO:EOF
  90.  
  91.  
  92. :ParseEDID
  93. :: Search 4 locations for "marker strings"
  94. FOR /L %%E IN (1,1,54) DO SHIFT
  95. IF /I "%1 %2 %3 %4"=="00 00 00 FC" CALL :Parse Model   56 %*
  96. IF /I "%1 %2 %3 %4"=="00 00 00 FF" CALL :Parse Serial  56 %*
  97. FOR /L %%E IN (1,1,18) DO SHIFT
  98. IF /I "%1 %2 %3 %4"=="00 00 00 FC" CALL :Parse Model   74 %*
  99. IF /I "%1 %2 %3 %4"=="00 00 00 FF" CALL :Parse Serial  74 %*
  100. FOR /L %%E IN (1,1,18) DO SHIFT
  101. IF /I "%1 %2 %3 %4"=="00 00 00 FC" CALL :Parse Model   92 %*
  102. IF /I "%1 %2 %3 %4"=="00 00 00 FF" CALL :Parse Serial  92 %*
  103. FOR /L %%E IN (1,1,18) DO SHIFT
  104. IF /I "%1 %2 %3 %4"=="00 00 00 FC" CALL :Parse Model  110 %*
  105. IF /I "%1 %2 %3 %4"=="00 00 00 FF" CALL :Parse Serial 110 %*
  106. GOTO:EOF
  107.  
  108.  
  109. :Parse
  110. :: Remember what we're parsing here
  111. SET What=%1
  112. :: Move to the start of the "marker"
  113. FOR /L %%F IN (1,1,%2) DO SHIFT
  114. :: Read and store 9 hexadecimal characters
  115. SET RawEDID=%1,%2,%3,%4,%5,%6,%7,%8,%9
  116. :: Move 9 positions forward
  117. FOR /L %%F IN (1,1,9) DO SHIFT
  118. :: Read and append the next 9 hexadecimal characters
  119. SET RawEDID=!RawEDID!,%1,%2,%3,%4,%5,%6,%7,%8,%9
  120. :: Remove the "marker"
  121. SET RawEDID=%RawEDID:~12%
  122. :: Start the hexadecimal to ASCII conversion
  123. SET RawEDIDStr=
  124. FOR %%G IN (%RawEDID%) DO (
  125. 	CALL :Hex2Str %%G
  126. 	SET RawEDIDStr=!RawEDIDStr!!Char!
  127. )
  128. :: Trim the result
  129. SET EDIDStr=
  130. FOR %%G IN (%RawEDIDStr%) DO SET EDIDStr=!EDIDStr! %%G
  131. :: Return the result to the value whose
  132. :: NAME was stored in the variable WHAT.
  133. SET %What%=%EDIDStr:~1%
  134. GOTO:EOF
  135.  
  136.  
  137. :Hex2Str
  138. :: Default is a space
  139. (SET Char= )
  140. :: Brute force conversion of valid characters
  141. IF /I "%~1"=="23" SET Char=#
  142. IF /I "%~1"=="24" SET Char=$
  143. IF /I "%~1"=="27" SET Char='
  144. IF /I "%~1"=="28" SET Char=(
  145. IF /I "%~1"=="29" SET Char=)
  146. IF /I "%~1"=="2A" SET Char=*
  147. IF /I "%~1"=="2B" SET Char=+
  148. IF /I "%~1"=="2C" SET Char=,
  149. IF /I "%~1"=="2D" SET Char=-
  150. IF /I "%~1"=="2E" SET Char=.
  151. IF /I "%~1"=="2F" SET Char=/
  152. IF /I "%~1"=="30" SET Char=0
  153. IF /I "%~1"=="31" SET Char=1
  154. IF /I "%~1"=="32" SET Char=2
  155. IF /I "%~1"=="33" SET Char=3
  156. IF /I "%~1"=="34" SET Char=4
  157. IF /I "%~1"=="35" SET Char=5
  158. IF /I "%~1"=="36" SET Char=6
  159. IF /I "%~1"=="37" SET Char=7
  160. IF /I "%~1"=="38" SET Char=8
  161. IF /I "%~1"=="39" SET Char=9
  162. IF /I "%~1"=="3A" SET Char=:
  163. IF /I "%~1"=="3B" SET Char=;
  164. IF /I "%~1"=="3D" SET Char==
  165. IF /I "%~1"=="3F" SET Char=?
  166. IF /I "%~1"=="40" SET Char=@
  167. IF /I "%~1"=="41" SET Char=A
  168. IF /I "%~1"=="42" SET Char=B
  169. IF /I "%~1"=="43" SET Char=C
  170. IF /I "%~1"=="44" SET Char=D
  171. IF /I "%~1"=="45" SET Char=E
  172. IF /I "%~1"=="46" SET Char=F
  173. IF /I "%~1"=="47" SET Char=G
  174. IF /I "%~1"=="48" SET Char=H
  175. IF /I "%~1"=="49" SET Char=I
  176. IF /I "%~1"=="4A" SET Char=J
  177. IF /I "%~1"=="4B" SET Char=K
  178. IF /I "%~1"=="4C" SET Char=L
  179. IF /I "%~1"=="4D" SET Char=M
  180. IF /I "%~1"=="4E" SET Char=N
  181. IF /I "%~1"=="4F" SET Char=O
  182. IF /I "%~1"=="50" SET Char=P
  183. IF /I "%~1"=="51" SET Char=Q
  184. IF /I "%~1"=="52" SET Char=R
  185. IF /I "%~1"=="53" SET Char=S
  186. IF /I "%~1"=="54" SET Char=T
  187. IF /I "%~1"=="55" SET Char=U
  188. IF /I "%~1"=="56" SET Char=V
  189. IF /I "%~1"=="57" SET Char=W
  190. IF /I "%~1"=="58" SET Char=X
  191. IF /I "%~1"=="59" SET Char=Y
  192. IF /I "%~1"=="5A" SET Char=Z
  193. IF /I "%~1"=="5B" SET Char=[
  194. IF /I "%~1"=="5C" SET Char=\
  195. IF /I "%~1"=="5D" SET Char=]
  196. IF /I "%~1"=="5F" SET Char=_
  197. IF /I "%~1"=="60" SET Char=`
  198. IF /I "%~1"=="61" SET Char=a
  199. IF /I "%~1"=="62" SET Char=b
  200. IF /I "%~1"=="63" SET Char=c
  201. IF /I "%~1"=="64" SET Char=d
  202. IF /I "%~1"=="65" SET Char=e
  203. IF /I "%~1"=="66" SET Char=f
  204. IF /I "%~1"=="67" SET Char=g
  205. IF /I "%~1"=="68" SET Char=h
  206. IF /I "%~1"=="69" SET Char=i
  207. IF /I "%~1"=="6A" SET Char=j
  208. IF /I "%~1"=="6B" SET Char=k
  209. IF /I "%~1"=="6C" SET Char=l
  210. IF /I "%~1"=="6D" SET Char=m
  211. IF /I "%~1"=="6E" SET Char=n
  212. IF /I "%~1"=="6F" SET Char=o
  213. IF /I "%~1"=="70" SET Char=p
  214. IF /I "%~1"=="71" SET Char=q
  215. IF /I "%~1"=="72" SET Char=r
  216. IF /I "%~1"=="73" SET Char=s
  217. IF /I "%~1"=="74" SET Char=t
  218. IF /I "%~1"=="75" SET Char=u
  219. IF /I "%~1"=="76" SET Char=v
  220. IF /I "%~1"=="77" SET Char=w
  221. IF /I "%~1"=="78" SET Char=x
  222. IF /I "%~1"=="79" SET Char=y
  223. IF /I "%~1"=="7A" SET Char=z
  224. IF /I "%~1"=="7B" SET Char={
  225. IF /I "%~1"=="7D" SET Char=}
  226. IF /I "%~1"=="7F" SET Char=
  227. IF /I "%~1"=="80" SET Char=€
  228. IF /I "%~1"=="81" SET Char=
  229. IF /I "%~1"=="82" SET Char=‚
  230. IF /I "%~1"=="83" SET Char=ƒ
  231. IF /I "%~1"=="84" SET Char=„
  232. IF /I "%~1"=="85" SET Char=…
  233. IF /I "%~1"=="86" SET Char=†
  234. IF /I "%~1"=="87" SET Char=‡
  235. IF /I "%~1"=="88" SET Char=ˆ
  236. IF /I "%~1"=="89" SET Char=‰
  237. IF /I "%~1"=="8A" SET Char=Š
  238. IF /I "%~1"=="8B" SET Char=‹
  239. IF /I "%~1"=="8C" SET Char=Œ
  240. IF /I "%~1"=="8D" SET Char=
  241. IF /I "%~1"=="8E" SET Char=Ž
  242. IF /I "%~1"=="8F" SET Char=
  243. IF /I "%~1"=="90" SET Char=
  244. IF /I "%~1"=="91" SET Char=‘
  245. IF /I "%~1"=="92" SET Char=’
  246. IF /I "%~1"=="93" SET Char=“
  247. IF /I "%~1"=="94" SET Char=”
  248. IF /I "%~1"=="95" SET Char=•
  249. IF /I "%~1"=="96" SET Char=–
  250. IF /I "%~1"=="97" SET Char=—
  251. IF /I "%~1"=="98" SET Char=˜
  252. IF /I "%~1"=="99" SET Char=™
  253. IF /I "%~1"=="9A" SET Char=š
  254. IF /I "%~1"=="9B" SET Char=›
  255. IF /I "%~1"=="9C" SET Char=œ
  256. IF /I "%~1"=="9D" SET Char=
  257. IF /I "%~1"=="9E" SET Char=ž
  258. IF /I "%~1"=="9F" SET Char=Ÿ
  259. IF /I "%~1"=="A0" SET Char= 
  260. IF /I "%~1"=="A1" SET Char=¡
  261. IF /I "%~1"=="A2" SET Char=¢
  262. IF /I "%~1"=="A3" SET Char=£
  263. IF /I "%~1"=="A4" SET Char=¤
  264. IF /I "%~1"=="A5" SET Char=¥
  265. IF /I "%~1"=="A6" SET Char=¦
  266. IF /I "%~1"=="A7" SET Char=§
  267. IF /I "%~1"=="A8" SET Char=¨
  268. IF /I "%~1"=="A9" SET Char=©
  269. IF /I "%~1"=="AA" SET Char=ª
  270. IF /I "%~1"=="AB" SET Char=«
  271. IF /I "%~1"=="AC" SET Char=¬
  272. IF /I "%~1"=="AD" SET Char=­
  273. IF /I "%~1"=="AE" SET Char=®
  274. IF /I "%~1"=="AF" SET Char=¯
  275. GOTO:EOF
  276.  
  277.  
  278. :Syntax
  279. ECHO.
  280. ECHO DispEDID.bat,  Version 1.01 for Windows XP
  281. ECHO Read and display your monitor's EDID asset information
  282. ECHO.
  283. ECHO Usage:  DISPEDID
  284. ECHO.
  285. ECHO Note:   Though this batch file might work in Windows 2000, Server 2003
  286. ECHO         and Vista, it has been tested in Windows XP Professional only.
  287. ECHO.
  288. ECHO Based on a VBScript by Michael Baird:
  289. ECHO http://cwashington.netreach.net/depo/view.asp?Index=980^&ScriptType=vbscript
  290. ECHO.
  291. ECHO Written by Rob van der Woude
  292. ECHO http://www.robvanderwoude.com
  293.  
  294. IF "%OS%"=="Windows_NT" ENDLOCAL
  295.  

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