Oct 16 2005

Windows Hack

Microsoft XP Professional comes with a few handy Visual Basic script files. In your C:\WINDOWS\SYSTEM32 directory you will find PRNJOBS.VBS and PRNMNGR.VBS amongst other script files. As you can gather from the name of these files, they related to printer functionality. Cay Horstmann, my former Computer Science instructor, strongly encouraged his students to always explore and learn from the files in any Open Source software and/or Operating System we use. With that same hacker spirit in mind, feel free to see how Microsoft hacks Visual Basic by opening up these scripts in your favorite text editor. Who knows, you might to learn something new. Oh, by the way, another of my Computer Science instructors was famed science fiction and popular science author Rudy Rucker and he taught me to keep a blog! Haha. Maybe I should have named this entry as ‘Windows Hack and Name Dropping.’


Sep 8 2005

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