Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for defprn.vbs

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

  1. ' Check for command line arguments (none required)
  2. If WScript.Arguments.Count Then Syntax
  3.  
  4. ' Connect to shell
  5. Set WshShell = WScript.CreateObject("WScript.Shell")
  6.  
  7. ' Read printer info from registry
  8. strPrn = WshShell.RegRead("HKCU\Printers\DeviceOld")
  9.  
  10. ' Format printer info
  11. arrPrn   = Split( strPrn, ",", -1, vbTextCompare )
  12. strDescr = arrPrn(0)
  13. arrPort  = Split( arrPrn(2), ":", -1, vbTextCompare )
  14. strPort  = arrPort(0)
  15.  
  16. ' Display the result
  17. strMsg = vbCrLf & "Default printer is " _
  18.        & strDescr & " on " & strPort
  19. WScript.Echo strMsg
  20.  
  21.  
  22. Sub Syntax()
  23. 	strMsg = vbCrLf _
  24. 	       & "DefPrn.vbs,  Version 1.00" & vbCrLf _
  25. 	       & "Display default printer and port" _
  26. 	       & vbCrLf & vbCrLf _
  27. 	       & "Usage:  CSCRIPT.EXE  DEFPRN.VBS" _
  28. 	       & vbCrLf & vbCrLf _
  29. 	       & "Written by Rob van der Woude" & vbCrLf _
  30. 	       & "http://www.robvanderwoude.com"
  31. 	WScript.Echo strMsg
  32. 	WScript.Quit(1)
  33. End Sub
  34.  

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