A colleague of mine needed a way to find out what is set as the default printer for many NT4 workstations, so that he could modify static settings for some of the 3rd party software packages that we distribute. Most people are connected to network printers, although there are a few who have their own local printer.
I had to do a lot of searching (web searches) and, through trial and error, I finally came up with the following solution. It's not perfect but seems, in our environment, to be reliable with testing on several machines in different locations.
I know that Win32::Registry is considered to be obsolete, but it does the job well for this purpose.
or die "Can't open this key: $^E";
my ($type, $value);
$pval->QueryValueEx("Device", $type, $value) or die "No Device Found:
print "Here's the default printer for this user: $value\n";
It probably won't on WIN2000 because the registries are different but I will take a look tomorrow to see which is correct (I will have access to a couple of these then).
I will let you know what I come up with.
I am simply a newbie when it comes to perl. But I am running Windows 2000 Pro. and the script worked for me.
Here is my output:
Here's the default printer for this user: hp deskjet 842c series,winspool,LPT1: