Advertisement
Guest User

Untitled

a guest
Sep 20th, 2010
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 27.71 KB | None | 0 0
  1. '# -------------------------------------------------------------------
  2. '# SystemInfoReporter Version 0.05
  3. '# Copyright (C) 2010
  4. '# Script Authors: Rob Sanders
  5. '# Last edit: Sept 20, 2010
  6. '#
  7. '# Collect Computer information and write the data to a csv file
  8. '# Developed for the Hospital Computer re-deployment project
  9. '#
  10. '# Changes Sept 20, 2010:
  11. '# Added Dual Monitor info gathering Code by: Michael Baird
  12. '# Removed and modified some of the WMI data being collected
  13. '# Removed the user input for file locations
  14. '# hard coded the file locations
  15. '#
  16. '# Changes March 22, 2010:
  17. '# Added user input variables for file locations
  18. '# Added error handling to validate user input
  19. '# Added error handling to check if source file exists
  20. '# -------------------------------------------------------------------
  21.  
  22. ' Start the script here
  23. Call GetInfo
  24.  
  25. Sub GetInfo
  26.  
  27. 'Constants for FileSystemObject
  28. Const FOR_READING = 1
  29. Const FOR_WRITING = 2
  30. Const FOR_APPENDING = 8
  31.  
  32. strInputFile = InputBox("Enter the Path and Filename for the file with the list of Computer Names")
  33. strSaveFile = InputBox("Enter the Save location for the Data file")
  34. 'strInputFile = "\\nas1\users\Sander\My Documents\Scripts\CompList.txt"
  35. 'strSaveFile = "\\nas1\users\Sander\My Documents\Scripts\results"
  36.  
  37. strFileOutput = strSaveFile & "\" & "Computer_SystemInfo.csv"
  38.  
  39. If strInputFile = "" Or strFileOutput = "" Then
  40. WScript.Echo "No paths were entered"
  41. WScript.Echo "The program has ended"
  42. WScript.Quit
  43. End If
  44.  
  45. ' Create a Script Runtime FileSystemObject.
  46. Set objFSO = CreateObject("Scripting.FileSystemObject")
  47.  
  48.  
  49. If Not objFSO.FileExists(strInputFile) Then
  50. WScript.Echo "The Path or File for " & strInputFile & " does not exist." & vbCrLf & "Re-Run the program and try again"
  51. WScript.Echo "The program has ended"
  52. WScript.Quit
  53. Else
  54.  
  55. If Not objFSO.FolderExists(strSaveFile) Then
  56. WScript.Echo "The Path " & strSaveFile & " does not exist."
  57. WScript.Echo "The program has ended"
  58. WScript.Quit
  59. Else
  60.  
  61. ' Check to see if the output file exists, If so, open it for writing or appending.
  62. ' If not, create if and open it for writing.
  63.  
  64. If objFSO.FileExists(strFileOutput) Then
  65. Set objOutputFile = objFSO.OpenTextFile(strFileOutput, FOR_APPENDING)
  66. Else
  67. Set objOutputFile = objFSO.CreateTextFile(strFileOutput)
  68. End If
  69.  
  70. ' Write header for File. Current date and header, and LINE space
  71. objOutPutFile.WriteLine "PC/Server System WMI Information" & _
  72. vbCrLf & "Author: Rob Sanders" & vbCrLf & "Information collected on: " & Now & vbCrLf & vbCrLf & String(30, "-") & vbCrLf
  73.  
  74. ' Creates headers in File
  75. objOutputFile.Writeline "Computer Name, Model, Manufacturer, RAM (MB) ,Serial No., ,Monitor Serial 1,Monitor Model 1,Monitor Serial 2,Monitor Model 2,Monitor Serial 3,Monitor Model 3"
  76.  
  77. ' Import our computer list file into a Dictionary
  78. Set objDictionary = CreateObject("Scripting.Dictionary")
  79. Set objFile = objFSO.OpenTextFile (strInputFile, FOR_READING)
  80. i = 0
  81. Do Until objFile.AtEndOfStream
  82. strNextLine = objFile.ReadLine
  83. If strNextLine <> "" Then
  84. objDictionary.Add i, strNextLine
  85. End If
  86. i = i + 1
  87. Loop
  88. objFile.Close
  89.  
  90. 'Ping remote computer to see if it is turned on before trying to collect the information.
  91. 'If inaccessible, display error message.
  92. For Each strComputer In objDictionary.Items
  93. Set objShell = CreateObject("WScript.Shell")
  94. Set objScriptExec = objShell.Exec("ping -n 1 -w 1000 " & strComputer)
  95. strPingResults = LCase(objScriptExec.StdOut.ReadAll)
  96. If InStr(strPingResults, "reply from") Then
  97.  
  98. 'Calls the computer, start of pull and writes info into document
  99. Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  100.  
  101. 'Computer name, Manufacturer, Model, RAM converts the RAM value to MB's
  102. Set colSettings = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
  103. For Each objComputer In colsettings
  104. objOutputFile.Write objComputer.Name &"," & objComputer.Model & "," & objComputer.Manufacturer & "," & round((objComputer.TotalPhysicalMemory / 1024)/1024,0)
  105. Next
  106.  
  107. 'Get the Serial Number
  108. Set colItems = objWMIService.ExecQuery ("Select * from Win32_BIOS",,48)
  109. For Each objItem In colItems
  110. objOutputFile.Write "," & objItem.SerialNumber
  111. Next
  112.  
  113. ' Now get all the Monitor Info
  114. 'gstrOutput = gstrOutput & GetMonitorInfo() & vbNewLine
  115. 'WScript.Echo gstrOutput
  116. objOutputFile.Write ", ," & GetMonitorInfo() & vbNewLine
  117.  
  118. Else
  119. 'WScript.Echo strComputer & " not found..."
  120. objOutputFile.Write "*** " & strComputer & " *** NOT Found" & vbCrLf
  121. Err.Clear
  122. End If
  123. Next
  124.  
  125. WScript.Echo "All Finished, go have a look..." & vbCrLf & "At - " & strFileOutput
  126.  
  127. End If
  128.  
  129. End If
  130.  
  131. End Sub
  132.  
  133.  
  134.  
  135.  
  136.  
  137. 'DISPLAY_REGKEY sets the regkey where displays are found. Don't change except for debugging
  138. 'I only change it when I am looking at a .REG file that someone sent me saying that the
  139. 'code doesn't work.
  140. Const DISPLAY_REGKEY="HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY\"
  141. 'sets the debug outfile (use format like c:\debug.txt)
  142. Const DEBUGFILE="NUL"
  143. 'if set to 1 then output debug info to DEBUGFILE (also writes debug to screen if running under cscript.exe)
  144. Const DEBUGMODE=0
  145. 'The ForceCscript subroutine forces execution under CSCRIPT.EXE/Prevents execution
  146. 'under WSCRIPT.EXE -- useful when debugging
  147. 'ForceCScript
  148.  
  149. DebugOut "Execution Started " & cstr(now)
  150. 'wscript.echo GetMonitorInfo() 'just write the output to screen
  151. DebugOut "Execution Completed " & cstr(now)
  152.  
  153. 'This is the main function. It calls everything else
  154. 'in the correct order.
  155. Function GetMonitorInfo()
  156.  
  157. debugout "Getting all display devices"
  158. arrAllDisplays=GetAllDisplayDevicesInReg()
  159. debugout "Filtering display devices to monitors"
  160. arrAllMonitors=GetAllMonitorsFromAllDisplays(arrAllDisplays)
  161. debugout "Filtering monitors to active monitors"
  162. arrActiveMonitors=GetActiveMonitorsFromAllMonitors(arrAllMonitors)
  163.  
  164. if ubound(arrActiveMonitors)=0 and arrActiveMonitors(0)="{ERROR}" Then
  165. debugout "No active monitors found"
  166. strFormattedMonitorInfo="[Monitor_1]" & vbcrlf & "Monitor=Not Found" & vbcrlf & vbcrlf
  167. else
  168. debugout "Found active monitors"
  169. debugout "Retrieving EDID for all active monitors"
  170. arrActiveEDID=GetEDIDFromActiveMonitors(arrActiveMonitors)
  171. debugout "Parsing EDID/Windows data"
  172. arrParsedMonitorInfo=GetParsedMonitorInfo(arrActiveEDID,arrActiveMonitors)
  173. debugout "Formatting parsed data"
  174. strFormattedMonitorInfo=GetFormattedMonitorInfo(arrParsedMonitorInfo)
  175. end If
  176.  
  177. debugout "Data retrieval completed"
  178. GetMonitorInfo=strFormattedMonitorInfo
  179.  
  180. End Function
  181.  
  182. 'this function formats the parsed array for display
  183. 'this is where the final output is generated
  184. 'it is the one you will most likely want to
  185. 'customize to suit your needs
  186. Function GetFormattedMonitorInfo(arrParsedMonitorInfo)
  187. ' Version 1.0
  188. ' Amended by Krystian Karia
  189. ' Written by Michael Baird
  190.  
  191. ' Amended for the GetInfo Main Script. To
  192. ' put monitor details at the end of the results
  193. ' of the current results from GetInfo.
  194.  
  195. for tmpctr=0 to ubound(arrParsedMonitorInfo)
  196. tmpResult=split(arrParsedMonitorInfo(tmpctr),"|||")
  197. ' tmpOutput=tmpOutput & "[Monitor_" & cstr(tmpctr+1) & "]" & VbCrLf
  198. ' tmpOutput=tmpOutput & "EDID_VESAManufacturerID=" & tmpResult(1) & VbCrLf
  199. ' tmpOutput=tmpOutput & "EDID_DeviceID=" & tmpResult(3) & VbCrLf
  200. ' tmpOutput=tmpOutput & "EDID_ManufactureDate=" & tmpResult(2) & VbCrLf
  201. ' tmpOutput=tmpOutput & "EDID_SerialNumber=" & tmpResult(0) & VbCrLf
  202. ' tmpOutput=tmpOutput & "EDID_ModelName=" & tmpResult(4) & VbCrLf
  203. ' tmpOutput=tmpOutput & "EDID_Version=" & tmpResult(5) & VbCrLf
  204. ' tmpOutput=tmpOutput & "Windows_VESAID=" & tmpResult(6) & VbCrLf
  205. ' tmpOutput=tmpOutput & "Windows_PNPID=" & tmpResult(7) & vbcrlf & VbCrLf
  206.  
  207. ' Custom output for VendorInfo Script
  208. tmpOutput=tmpOutput & tmpResult(0) & ","
  209. tmpOutput=tmpOutput & tmpResult(4) & ","
  210.  
  211. Next
  212.  
  213. GetFormattedMonitorInfo=tmpOutput
  214.  
  215. End Function
  216.  
  217. 'This function returns an array of all subkeys of the regkey defined by DISPLAY_REGKEY
  218. '(typically this should be "HKLM\SYSTEM\CurrentControlSet\Enum\DISPLAY")
  219. Function GetAllDisplayDevicesInReg()
  220. Dim arrResult()
  221. ReDim arrResult(0)
  222. intArrResultIndex=-1
  223. arrtmpkeys=RegEnumKeys(DISPLAY_REGKEY)
  224. If vartype(arrtmpkeys)<>8204 then
  225. arrResult(0)="{ERROR}"
  226. GetAllDisplayDevicesInReg=false
  227. DebugOut "Display=Can't enum subkeys of display regkey"
  228. Else
  229. For tmpctr=0 to ubound(arrtmpkeys)
  230. arrtmpkeys2=RegEnumKeys(DISPLAY_REGKEY & arrtmpkeys(tmpctr))
  231. For tmpctr2 = 0 to ubound(arrtmpkeys2)
  232. intArrResultIndex=intArrResultIndex+1
  233. ReDim preserve arrResult(intArrResultIndex)
  234. arrResult(intArrResultIndex)=DISPLAY_REGKEY & arrtmpkeys(tmpctr) & "\" & arrtmpkeys2(tmpctr2)
  235. DebugOut "Display=" & arrResult(intArrResultIndex)
  236. Next
  237. Next
  238. End if
  239. GetAllDisplayDevicesInReg=arrResult
  240. End Function
  241.  
  242. 'This function is passed an array of regkeys as strings
  243. 'and returns an array containing only those that have a
  244. 'hardware id value appropriate to a monitor.
  245. Function GetAllMonitorsFromAllDisplays(arrRegKeys)
  246. dim arrResult()
  247. redim arrResult(0)
  248. intArrResultIndex=-1
  249. for tmpctr=0 to ubound(arrRegKeys)
  250. if IsDisplayDeviceAMonitor(arrRegKeys(tmpctr)) then
  251. intArrResultIndex=intArrResultIndex+1
  252. redim preserve arrResult(intArrResultIndex)
  253. arrResult(intArrResultIndex)=arrRegKeys(tmpctr)
  254. debugout "Monitor=" & arrResult(intArrResultIndex)
  255. end if
  256. next
  257. if intArrResultIndex=-1 then
  258. arrResult(0)="{ERROR}"
  259. debugout "Monitor=Unable to locate any monitors"
  260. end if
  261. GetAllMonitorsFromAllDisplays=arrResult
  262. End Function
  263.  
  264. 'this function is passed a regsubkey as a string
  265. 'and determines if it is a monitor
  266. 'returns boolean
  267. Function IsDisplayDeviceAMonitor(strDisplayRegKey)
  268. arrtmpResult=RegGetMultiStringValue(strDisplayRegKey,"HardwareID")
  269. strtmpResult="|||" & join(arrtmpResult,"|||") & "|||"
  270. if instr(lcase(strtmpResult),"|||monitor\")=0 then
  271. debugout "MonitorCheck='" & strDisplayRegKey & "'|||is not a monitor"
  272. IsDisplayDeviceAMonitor=false
  273. else
  274. debugout "MonitorCheck='" & strDisplayRegKey & "'|||is a monitor"
  275. IsDisplayDeviceAMonitor=true
  276. end if
  277. End Function
  278.  
  279. 'This function is passed an array of regkeys as strings
  280. 'and returns an array containing only those that have a
  281. 'subkey named "Control"...establishing that they are current.
  282. Function GetActiveMonitorsFromAllMonitors(arrRegKeys)
  283. dim arrResult()
  284. redim arrResult(0)
  285. intArrResultIndex=-1
  286. for tmpctr=0 to ubound(arrRegKeys)
  287. if IsMonitorActive(arrRegKeys(tmpctr)) then
  288. intArrResultIndex=intArrResultIndex+1
  289. redim preserve arrResult(intArrResultIndex)
  290. arrResult(intArrResultIndex)=arrRegKeys(tmpctr)
  291. debugout "ActiveMonitor=" & arrResult(intArrResultIndex)
  292. end if
  293. next
  294.  
  295. if intArrResultIndex=-1 then
  296. arrResult(0)="{ERROR}"
  297. debugout "ActiveMonitor=Unable to locate any active monitors"
  298. end if
  299. GetActiveMonitorsFromAllMonitors=arrResult
  300. End Function
  301.  
  302. 'this function is passed a regsubkey as a string
  303. 'and determines if it is an active monitor
  304. 'returns boolean
  305. Function IsMonitorActive(strMonitorRegKey)
  306. arrtmpResult=RegEnumKeys(strMonitorRegKey)
  307. strtmpResult="|||" & join(arrtmpResult,"|||") & "|||"
  308. if instr(lcase(strtmpResult),"|||control|||")=0 then
  309. debugout "ActiveMonitorCheck='" & strMonitorRegKey & "'|||is not active"
  310. IsMonitorActive=false
  311. else
  312. debugout "ActiveMonitorCheck='" & strMonitorRegKey & "'|||is active"
  313. IsMonitorActive=true
  314. end if
  315. End Function
  316.  
  317. 'This function is passed an array of regkeys as strings
  318. 'and returns an array containing the corresponding contents
  319. 'of the EDID value (in string format) for the "Device Parameters"
  320. 'subkey of the specified key
  321. Function GetEDIDFromActiveMonitors(arrRegKeys)
  322. dim arrResult()
  323. redim arrResult(0)
  324. intArrResultIndex=-1
  325. for tmpctr=0 to ubound(arrRegKeys)
  326. strtmpResult=GetEDIDForMonitor(arrRegKeys(tmpctr))
  327. intArrResultIndex=intArrResultIndex+1
  328. redim preserve arrResult(intArrResultIndex)
  329. arrResult(intArrResultIndex)=strtmpResult
  330. debugout "GETEDID=" & arrRegKeys(tmpctr) & "|||EDID,Yes"
  331. next
  332.  
  333. if intArrResultIndex=-1 then
  334. arrResult(0)="{ERROR}"
  335. debugout "EDID=Unable to retrieve any edid"
  336. end if
  337. GetEDIDFromActiveMonitors=arrResult
  338. End Function
  339.  
  340. 'given the regkey of a specific monitor
  341. 'this function returns the EDID info
  342. 'in string format
  343. Function GetEDIDForMonitor(strMonitorRegKey)
  344. arrtmpResult=RegGetBinaryValue(strMonitorRegKey & "\Device Parameters","EDID")
  345. if vartype(arrtmpResult) <> 8204 then
  346. debugout "GetEDID=No EDID Found|||" & strMonitorRegKey
  347. GetEDIDForMonitor="{ERROR}"
  348. else
  349. for each bytevalue in arrtmpResult
  350. strtmpResult=strtmpResult & chr(bytevalue)
  351. next
  352. debugout "GetEDID=EDID Found|||" & strMonitorRegKey
  353. debugout "GetEDID_Result=" & GetHexFromString(strtmpResult)
  354. GetEDIDForMonitor=strtmpResult
  355. end if
  356. End Function
  357.  
  358. 'passed a given string this function
  359. 'returns comma seperated hex values
  360. 'for each byte
  361. Function GetHexFromString(strText)
  362. for tmpctr=1 to len(strText)
  363. tmpresult=tmpresult & right( "0" & hex(asc(mid(strText,tmpctr,1))),2) & ","
  364. next
  365. GetHexFromString=left(tmpresult,len(tmpresult)-1)
  366. End Function
  367.  
  368. 'this function should be passed two arrays with the same
  369. 'number of elements. array 1 should contain the
  370. 'edid information that corresponds to the active monitor
  371. 'regkey found in the same element of array 2
  372. 'Why not use a 2D array or a dictionary object?.
  373. 'I guess I'm just lazy
  374. Function GetParsedMonitorInfo(arrActiveEDID,arrActiveMonitors)
  375. dim arrResult()
  376. for tmpctr=0 to ubound(arrActiveEDID)
  377. strSerial=GetSerialFromEDID(arrActiveEDID(tmpctr))
  378. strMfg=GetMfgFromEDID(arrActiveEDID(tmpctr))
  379. strMfgDate=GetMfgDateFromEDID(arrActiveEDID(tmpctr))
  380. strDev=GetDevFromEDID(arrActiveEDID(tmpctr))
  381. strModel=GetModelFromEDID(arrActiveEDID(tmpctr))
  382. strEDIDVer=GetEDIDVerFromEDID(arrActiveEDID(tmpctr))
  383. strWinVesaID=GetWinVESAIDFromRegKey(arrActiveMonitors(tmpctr))
  384. strWinPNPID=GetWinPNPFromRegKey(arrActiveMonitors(tmpctr))
  385. redim preserve arrResult(tmpctr)
  386. arrResult(tmpctr)=arrResult(tmpctr) & strSerial & "|||"
  387. arrResult(tmpctr)=arrResult(tmpctr) & strMfg & "|||"
  388. arrResult(tmpctr)=arrResult(tmpctr) & strMfgDate & "|||"
  389. arrResult(tmpctr)=arrResult(tmpctr) & strDev & "|||"
  390. arrResult(tmpctr)=arrResult(tmpctr) & strModel & "|||"
  391. arrResult(tmpctr)=arrResult(tmpctr) & strEDIDVer & "|||"
  392. arrResult(tmpctr)=arrResult(tmpctr) & strWinVesaID & "|||"
  393. arrResult(tmpctr)=arrResult(tmpctr) & strWinPNPID
  394. debugout arrResult(tmpctr)
  395. next
  396. GetParsedMonitorInfo=arrResult
  397. End Function
  398.  
  399. 'this is a simple string function to break the VESA monitor ID
  400. 'from the registry key
  401. Function GetWinVESAIDFromRegKey(strRegKey)
  402. if strRegKey="{ERROR}" then
  403. GetWinVESAIDFromRegKey="Bad Registry Info"
  404. exit function
  405. end if
  406. strtmpResult=right(strRegKey,len(strRegkey)-len(DISPLAY_REGKEY))
  407. strtmpResult=left(strtmpResult,instr(strtmpResult,"\")-1)
  408. GetWinVESAIDFromRegKey=strtmpResult
  409. End Function
  410.  
  411. 'this is a simple string function to break windows PNP device id
  412. 'from the registry key
  413. Function GetWinPNPFromRegKey(strRegKey)
  414. if strRegKey="{ERROR}" then
  415. GetWinPNPFromRegKey="Bad Registry Info"
  416. exit function
  417. end if
  418. strtmpResult=right(strRegKey,len(strRegkey)-len(DISPLAY_REGKEY))
  419. strtmpResult=right(strtmpResult,len(strtmpResult)-instr(strtmpResult,"\"))
  420. GetWinPNPFromRegKey=strtmpResult
  421. End Function
  422.  
  423. 'utilizes the GetDescriptorBlockFromEDID function
  424. 'to retrieve the serial number block
  425. 'from the EDID data
  426. Function GetSerialFromEDID(strEDID)
  427. 'a serial number descriptor will start with &H00 00 00 ff
  428. strTag=chr(&H00) & chr(&H00) & chr(&H00) & chr(&Hff)
  429. GetSerialFromEDID=GetDescriptorBlockFromEDID(strEDID,strTag)
  430. End Function
  431.  
  432. 'utilizes the GetDescriptorBlockFromEDID function
  433. 'to retrieve the model description block
  434. 'from the EDID data
  435. Function GetModelFromEDID(strEDID)
  436. 'a model number descriptor will start with &H00 00 00 fc
  437. strTag=chr(&H00) & chr(&H00) & chr(&H00) & chr(&Hfc)
  438. GetModelFromEDID=GetDescriptorBlockFromEDID(strEDID,strTag)
  439. End Function
  440.  
  441. 'This function parses a string containing EDID data
  442. 'and returns the information contained in one of the
  443. '4 custom "descriptor blocks" providing the data in the
  444. 'block is tagged wit a certain prefix
  445. 'if no descriptor is tagged with the specified prefix then
  446. 'function returns "Not Present in EDID"
  447. 'otherwise it returns the data found in the descriptor
  448. 'trimmed of its prefix tag and also trimmed of
  449. 'leading NULLs (chr(0)) and trailing linefeeds (chr(10))
  450. Function GetDescriptorBlockFromEDID(strEDID,strTag)
  451. if strEDID="{ERROR}" then
  452. GetDescriptorBlockFromEDID="Bad EDID"
  453. exit function
  454. end if
  455.  
  456. '*********************************************************************
  457. 'There are 4 descriptor blocks in edid at offset locations
  458. '&H36 &H48 &H5a and &H6c each block is 18 bytes long
  459. 'the model and serial numbers are stored in the vesa descriptor
  460. 'blocks in the edid.
  461. '*********************************************************************
  462. dim arrDescriptorBlock(3)
  463. arrDescriptorBlock(0)=mid(strEDID,&H36+1,18)
  464. arrDescriptorBlock(1)=mid(strEDID,&H48+1,18)
  465. arrDescriptorBlock(2)=mid(strEDID,&H5a+1,18)
  466. arrDescriptorBlock(3)=mid(strEDID,&H6c+1,18)
  467.  
  468. if instr(arrDescriptorBlock(0),strTag)>0 then
  469. strFoundBlock=arrDescriptorBlock(0)
  470. elseif instr(arrDescriptorBlock(1),strTag)>0 then
  471. strFoundBlock=arrDescriptorBlock(1)
  472. elseif instr(arrDescriptorBlock(2),strTag)>0 then
  473. strFoundBlock=arrDescriptorBlock(2)
  474. elseif instr(arrDescriptorBlock(3),strTag)>0 then
  475. strFoundBlock=arrDescriptorBlock(3)
  476. else
  477. GetDescriptorBlockFromEDID="Not Present in EDID"
  478. exit function
  479. end if
  480.  
  481. strResult=right(strFoundBlock,14)
  482. 'the data in the descriptor block will either fill the
  483. 'block completely or be terminated with a linefeed (&h0a)
  484. if instr(strResult,chr(&H0a))>0 then
  485. strResult=trim(left(strResult,instr(strResult,chr(&H0a))-1))
  486. else
  487. strResult=trim(strResult)
  488. end if
  489.  
  490. 'although it is not part of the edid spec (as far as i can tell) it seems as though the
  491. 'information in the descriptor will frequently be preceeded by &H00, this
  492. 'compensates for that
  493. if left(strResult,1)=chr(0) then strResult=right(strResult,len(strResult)-1)
  494.  
  495. GetDescriptorBlockFromEDID=strResult
  496. End Function
  497.  
  498. 'This function parses a string containing EDID data
  499. 'and returns the VESA manufacturer ID as a string
  500. 'the manufacturer ID is a 3 character identifier
  501. 'assigned to device manufacturers by VESA
  502. 'I guess that means you're not allowed to make an EDID
  503. 'compliant monitor unless you belong to VESA.
  504. Function GetMfgFromEDID(strEDID)
  505. if strEDID="{ERROR}" then
  506. GetMfgFromEDID="Bad EDID"
  507. exit function
  508. end if
  509.  
  510. 'the mfg id is 2 bytes starting at EDID offset &H08
  511. 'the id is three characters long. using 5 bits to represent
  512. 'each character. the bits are used so that 1=A 2=B etc..
  513. '
  514. 'get the data
  515. tmpEDIDMfg=mid(strEDID,&H08+1,2)
  516. Char1=0 : Char2=0 : Char3=0
  517. Byte1=asc(left(tmpEDIDMfg,1)) 'get the first half of the string
  518. Byte2=asc(right(tmpEDIDMfg,1)) 'get the first half of the string
  519. 'now shift the bits
  520. 'shift the 64 bit to the 16 bit
  521. if (Byte1 and 64) > 0 then Char1=Char1+16
  522. 'shift the 32 bit to the 8 bit
  523. if (Byte1 and 32) > 0 then Char1=Char1+8
  524. 'etc....
  525. if (Byte1 and 16) > 0 then Char1=Char1+4
  526. if (Byte1 and 8) > 0 then Char1=Char1+2
  527. if (Byte1 and 4) > 0 then Char1=Char1+1
  528.  
  529. 'the 2nd character uses the 2 bit and the 1 bit of the 1st byte
  530. if (Byte1 and 2) > 0 then Char2=Char2+16
  531. if (Byte1 and 1) > 0 then Char2=Char2+8
  532. 'and the 128,64 and 32 bits of the 2nd byte
  533. if (Byte2 and 128) > 0 then Char2=Char2+4
  534. if (Byte2 and 64) > 0 then Char2=Char2+2
  535. if (Byte2 and 32) > 0 then Char2=Char2+1
  536.  
  537. 'the bits for the 3rd character don't need shifting
  538. 'we can use them as they are
  539. Char3=Char3+(Byte2 and 16)
  540. Char3=Char3+(Byte2 and 8)
  541. Char3=Char3+(Byte2 and 4)
  542. Char3=Char3+(Byte2 and 2)
  543. Char3=Char3+(Byte2 and 1)
  544. tmpmfg=chr(Char1+64) & chr(Char2+64) & chr(Char3+64)
  545. GetMfgFromEDID=tmpmfg
  546. End Function
  547.  
  548. 'This function parses a string containing EDID data
  549. 'and returns the manufacture date in mm/yyyy format
  550. Function GetMfgDateFromEDID(strEDID)
  551. if strEDID="{ERROR}" then
  552. GetMfgDateFromEDID="Bad EDID"
  553. exit function
  554. end if
  555.  
  556. 'the week of manufacture is stored at EDID offset &H10
  557. tmpmfgweek=asc(mid(strEDID,&H10+1,1))
  558.  
  559. 'the year of manufacture is stored at EDID offset &H11
  560. 'and is the current year -1990
  561. tmpmfgyear=(asc(mid(strEDID,&H11+1,1)))+1990
  562.  
  563. 'store it in month/year format
  564. tmpmdt=month(dateadd("ww",tmpmfgweek,datevalue("1/1/" & tmpmfgyear))) & "/" & tmpmfgyear
  565. GetMfgDateFromEDID=tmpmdt
  566. End Function
  567.  
  568. 'This function parses a string containing EDID data
  569. 'and returns the device ID as a string
  570. Function GetDevFromEDID(strEDID)
  571. if strEDID="{ERROR}" then
  572. GetDevFromEDID="Bad EDID"
  573. exit function
  574. end if
  575. 'the device id is 2bytes starting at EDID offset &H0a
  576. 'the bytes are in reverse order.
  577. 'this code is not text. it is just a 2 byte code assigned
  578. 'by the manufacturer. they should be unique to a model
  579. tmpEDIDDev1=hex(asc(mid(strEDID,&H0a+1,1)))
  580. tmpEDIDDev2=hex(asc(mid(strEDID,&H0b+1,1)))
  581. if len(tmpEDIDDev1)=1 then tmpEDIDDev1="0" & tmpEDIDDev1
  582. if len(tmpEDIDDev2)=1 then tmpEDIDDev2="0" & tmpEDIDDev2
  583. tmpdev=tmpEDIDDev2 & tmpEDIDDev1
  584. GetDevFromEDID=tmpdev
  585. End Function
  586.  
  587. 'This function parses a string containing EDID data
  588. 'and returns the EDID version number as a string
  589. 'I should probably do this first and then not return any other data
  590. 'if the edid version exceeds 1.3 since most if this code probably
  591. 'won't work right if they change the spec drastically enough (which they probably
  592. 'won't do for backward compatability reasons thus negating my need to check and
  593. 'making this comment somewhat redundant)
  594. Function GetEDIDVerFromEDID(strEDID)
  595. if strEDID="{ERROR}" then
  596. GetEDIDVerFromEDID="Bad EDID"
  597. exit function
  598. end if
  599.  
  600. 'the version is at EDID offset &H12
  601. tmpEDIDMajorVer=asc(mid(strEDID,&H12+1,1))
  602.  
  603. 'the revision level is at EDID offset &H13
  604. tmpEDIDRev=asc(mid(strEDID,&H13+1,1))
  605.  
  606. tmpver=chr(48+tmpEDIDMajorVer) & "." & chr(48+tmpEDIDRev)
  607. GetEDIDVerFromEDID=tmpver
  608. End Function
  609.  
  610. 'simple function to provide an
  611. 'easier interface to the wmi registry functions
  612. Function RegEnumKeys(RegKey)
  613. hive=SetHive(RegKey)
  614. set objReg=GetWMIRegProvider()
  615. strKeyPath = right(RegKey,len(RegKey)-instr(RegKey,"\"))
  616. objReg.EnumKey Hive, strKeyPath, arrSubKeys
  617. RegEnumKeys=arrSubKeys
  618. End Function
  619.  
  620. 'simple function to provide an
  621. 'easier interface to the wmi registry functions
  622. Function RegGetStringValue(RegKey,RegValueName)
  623. hive=SetHive(RegKey)
  624. set objReg=GetWMIRegProvider()
  625. strKeyPath = right(RegKey,len(RegKey)-instr(RegKey,"\"))
  626. tmpreturn=objReg.GetStringValue(Hive, strKeyPath, RegValueName, RegValue)
  627. if tmpreturn=0 then
  628. RegGetStringValue=RegValue
  629. else
  630. RegGetStringValue="~{{<ERROR>}}~"
  631. end if
  632. End Function
  633.  
  634. 'simple function to provide an
  635. 'easier interface to the wmi registry functions
  636. Function RegGetMultiStringValue(RegKey,RegValueName)
  637. hive=SetHive(RegKey)
  638. set objReg=GetWMIRegProvider()
  639. strKeyPath = right(RegKey,len(RegKey)-instr(RegKey,"\"))
  640. tmpreturn=objReg.GetMultiStringValue(Hive, strKeyPath, RegValueName, RegValue)
  641. if tmpreturn=0 then
  642. RegGetMultiStringValue=RegValue
  643. else
  644. RegGetMultiStringValue="~{{<ERROR>}}~"
  645. end if
  646. End Function
  647.  
  648. 'simple function to provide an
  649. 'easier interface to the wmi registry functions
  650. Function RegGetBinaryValue(RegKey,RegValueName)
  651. hive=SetHive(RegKey)
  652. set objReg=GetWMIRegProvider()
  653. strKeyPath = right(RegKey,len(RegKey)-instr(RegKey,"\"))
  654. tmpreturn=objReg.GetBinaryValue(Hive, strKeyPath, RegValueName, RegValue)
  655. if tmpreturn=0 then
  656. RegGetBinaryValue=RegValue
  657. else
  658. RegGetBinaryValue="~{{<ERROR>}}~"
  659. end if
  660. End Function
  661.  
  662. 'simple function to provide a wmi registry provider
  663. 'to all the other registry functions (regenumkeys, reggetstringvalue, etc...)
  664. Function GetWMIRegProvider()
  665. strComputer = "."
  666. Set GetWMIRegProvider=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\default:StdRegProv")
  667. End Function
  668.  
  669. 'function to parse the specified hive
  670. 'from the registry functions above
  671. 'to all the other registry functions (regenumkeys, reggetstringvalue, etc...)
  672. Function SetHive(RegKey)
  673. HKEY_CLASSES_ROOT=&H80000000
  674. HKEY_CURRENT_USER=&H80000001
  675. HKEY_CURRENT_CONFIG=&H80000005
  676. HKEY_LOCAL_MACHINE=&H80000002
  677. HKEY_USERS=&H80000003
  678. strHive=left(RegKey,instr(RegKey,"\"))
  679. if strHive="HKCR\" or strHive="HKR\" then SetHive=HKEY_CLASSES_ROOT
  680. if strHive="HKCU\" then SetHive=HKEY_CURRENT_USER
  681. if strHive="HKCC\" then SetHive=HKEY_CURRENT_CONFIG
  682. if strHive="HKLM\" then SetHive=HKEY_LOCAL_MACHINE
  683. if strHive="HKU\" then SetHive=HKEY_USERS
  684. End Function
  685.  
  686. 'this sub forces execution under cscript
  687. 'it can be useful for debugging if your machine's
  688. 'default script engine is set to wscript
  689. Sub ForceCScript
  690. strCurrScriptHost=lcase(right(wscript.fullname,len(wscript.fullname)-len(wscript.path)-1))
  691. if strCurrScriptHost<>"cscript.exe" then
  692. set objFSO=CreateObject("Scripting.FileSystemObject")
  693. Set objShell = CreateObject("WScript.Shell")
  694. Set objArgs = WScript.Arguments
  695. strExecCmdLine=wscript.path & "\cscript.exe //nologo " & objfso.getfile(wscript.scriptfullname).shortpath
  696. For argctr = 0 to objArgs.Count - 1
  697. strExecArg=objArgs(argctr)
  698. if instr(strExecArg," ")>0 then strExecArg=chr(34) & strExecArg & chr(34)
  699. strExecAllArgs=strExecAllArgs & " " & strExecArg
  700. Next
  701. objShell.run strExecCmdLine & strExecAllArgs,1,false
  702. set objFSO = nothing
  703. Set objShell = nothing
  704. Set objArgs = nothing
  705. wscript.quit
  706. end if
  707. End Sub
  708.  
  709. 'allows for a pause at the end of execution
  710. 'currently used only for debugging
  711. Sub Pause
  712. set objStdin=wscript.stdin
  713. set objStdout=wscript.stdout
  714. objStdout.write "Press ENTER to continue..."
  715. strtmp=objStdin.readline
  716. end Sub
  717.  
  718. 'if debugmode=1 the writes dubug info to the specified
  719. 'file and if running under cscript also writes it to screen.
  720. Sub DebugOut(strDebugInfo)
  721. if DEBUGMODE=0 then exit sub
  722. strCurrScriptHost=lcase(right(wscript.fullname,len(wscript.fullname)-len(wscript.path)-1))
  723. if strCurrScriptHost="cscript.exe" then wscript.echo "Debug: " & strDebugInfo
  724. AppendFileMode=8
  725. set objDebugFSO=CreateObject("Scripting.FileSystemObject")
  726. set objDebugStream=objDebugFSO.OpenTextFile(DEBUGFILE,AppendFileMode,True,False)
  727. objDebugStream.writeline strDebugInfo
  728. objDebugStream.Close
  729. set objDebugStream=Nothing
  730. set objDebugFSO=Nothing
  731. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement