Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for getprint.vbs

(view source code of getprint.vbs as plain text)

  1. Option Explicit
  2.  
  3. Dim arrAssoc, arrKeys, arrSubKeys
  4. Dim i, j
  5. Dim objDic, objReg
  6. Dim strFileType, strLine, strKey, strSubKey, strSubSubKey, strValue
  7.  
  8. Const HKCR = &H80000000
  9.  
  10. ' No command line arguments required
  11. If WScript.Arguments.Count > 0 Then Syntax
  12.  
  13. Set objReg = GetObject( "winmgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv" )
  14. Set objDic = CreateObject( "Scripting.Dictionary" )
  15.  
  16. ' List all keys in the HKEY_CLASSES_ROOT hive
  17. objReg.EnumKey HKCR, "", arrKeys
  18.  
  19. For i = 0 To UBound( arrKeys )
  20. 	' Store registered extensions and their associated file types in a dictionary
  21. 	If Left( arrKeys(i), 1 ) = "." Then
  22. 		objReg.GetStringValue HKCR, arrKeys(i), "", strFileType
  23. 		objDic.Item( strFileType) = arrKeys(i)
  24. 	End If
  25. 	' Check if any commands are available for a file type
  26. 	strSubKey = arrKeys(i) & "\shell"
  27. 	objReg.EnumKey HKCR, strSubKey, arrSubKeys
  28. 	If IsArray( arrSubKeys ) Then
  29. 		strLine = ""
  30. 		For j = 0 To UBound( arrSubKeys )
  31. 			If Left( LCase( arrSubKeys(j) ), 5 ) = "print" Then
  32. 				' Skip DDE print commands
  33. 				strSubSubKey = arrKeys(i) & "\shell\" & arrSubKeys(j) & "\ddeexec"
  34. 				objReg.GetStringValue HKCR, strSubSubKey, "", strValue
  35. 				If Trim( strValue ) <> "" Then Exit For
  36. 				' Display the print command
  37. 				strSubSubKey = arrKeys(i) & "\shell\" & arrSubKeys(j) & "\command"
  38. 				objReg.GetStringValue HKCR, strSubSubKey, "", strValue
  39. 				strFileType = Split( strSubSubKey, "\" )(0)
  40. 				WScript.Echo objDic.Item( strFileType ) & vbTab _
  41. 				           & strFileType   & vbTab _
  42. 				           & arrSubKeys(j) & vbTab & strValue
  43. 			End If
  44. 		Next
  45. 	End If
  46. 	arrSubKeys = ""
  47. Next
  48.  
  49. Set objDic = Nothing
  50. Set objReg = Nothing
  51.  
  52.  
  53. Sub Syntax
  54. 	WScript.Echo vbCrLf _
  55. 	           & "GetPrint.vbs,  Version 2.01" _
  56. 	           & vbCrLf _
  57. 	           & "List Print and PrintTo commands for all registered file types" _
  58. 	           & vbCrLf & vbCrLf _
  59. 	           & "Usage:  CSCRIPT.EXE  //NoLogo  GETPRINT.VBS" _
  60. 	           & vbCrLf & vbCrLf _
  61. 	           & "Notes:  Only one file extension will be listed for each registered file type." _
  62. 	           & vbCrLf _
  63. 	           & "        This script will list (non-DDE) print commands for all registered file" _
  64. 	           & vbCrLf _
  65. 	           & "        types.  To find print commands for a specific file type, use ASSOC and" _
  66. 	           & vbCrLf _
  67. 	           & "        FINDSTR.  E.g. to find the print commands for font files (*.fon):" _
  68. 	           & vbCrLf & vbCrLf _
  69. 	           & "        ASSOC .fon" _
  70. 	           & vbCrLf & vbCrLf _
  71. 	           & "        .fon=fonfile" _
  72. 	           & vbCrLf & vbCrLf _
  73. 	           & "        CSCRIPT GETPRINT.VBS | FINDSTR /R /I /B /C:""fonfile""" _
  74. 	           & vbCrLf & vbCrLf _
  75. 	           & "        .fon    fonfile    print    C:\WINDOWS\System32\fontview.exe /p %1" _
  76. 	           & vbCrLf & vbCrLf _
  77. 	           & "Written by Rob van der Woude" _
  78. 	           & vbCrLf _
  79. 	           & "http://www.robvanderwoude.com"
  80. 	WScript.Quit 1
  81. End Sub
  82.  

page last uploaded: 2016-12-15, 11:20