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 = "HKCUSoftwareMicrosoftWindows "
   sRegVal = sRegVal & "NTCurrentVersionWindowsDevice"
   sDefault = ""

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

   GetDefaultPrinter = sDefault
End Function

Escape From XML »
« Eclipse Tool Tip #1: Getters and Setters
 
Related Posts
Recent Posts
 

No Comment

No comments yet

Leave a reply