Default Printer

This piece of code, simple as it is, took me a long while to develop. I am not well versed in Visual Basic and yet needed to find the default printer. I searched in a 1000+ page book, all over the internet, and after a lot of trial and error got it working. This Visual Basic script code block returns the default printer:

' Returns the default printer
Function GetDefaultPrinter()
   Set WshShell = WSCript.CreateObject("WScript.Shell")
   sRegVal = "HKCU\Software\Microsoft\Windows "
   sRegVal = sRegVal & "NT\CurrentVersion\Windows\Device"
   sDefault = ""

   sDefault = WshShell.RegRead(sRegVal)
   sDefault = Left(sDefault, InStr(sDefault, ",") - 1)

   GetDefaultPrinter = sDefault
End Function

Related posts:

  1. More Ways To Open A Doc
  2. Print HTML Using IE
  3. HP Printer Driver Wants To Phone Home
  4. Windows Hack
  5. Word To PDF

This entry was posted in TechKnow, Visual Basic. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*