WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Printing Information

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Determine the default printer on Windows NT

Keywords:   default printer windows NT

Question:

Is there any way to determine the default printer on windows NT 4.0. I do not want to change it or anything fancy like that.

Answer:

See the Printer Control Extender function pAddPrinter. pAddPrinter adds a printer to the list of supported printers for a server.

In NT, if you have a default printer set up, then in the registry under HKEY_USERS, look at the key that is NOT the .DEFAULT key (something like S-5-21-154348883-1354049292-227697207-500), and see what is set under the following. The defprt value should be something like: "HPLaserjet5,winspool,Ne02:".

key=RegOpenkey(@RegUsers, "")
who=RegQueryKeys(key)
mykey=ItemExtract(2,who,@tab)
RegClosekey(key)

defprt = RegQueryValue(@REGUSERS, "%mykey%\Software\Microsoft\WindowsNT\CurrentVersion\Windows[Device])

if defprt == "" 
	Message("Default Printer", "No Default Printer Set UP")
else
	Message("Default Printer", "Default printer is %defprt%")
endif

Related Question:

Does this work for network printers? I have already tried this and it can not find a value for defprt at System\...\Printers[Default]. I get an error unable to open (or create) subkey?
defkey="System\CurrentControlSet\Control\Print\Printers[Default]"

defprt = RegQueryValue(@REGCLASSES+5, defkey)

prtkey="System\CurrentControlSet\control\Print\Printers\"

portkey=strcat(prtkey,defprt,"[port]")

prtport=RegQueryValue(@REGMACHINE,portkey)

Message(defprt,prtport) 

Answer:

Good question. I poked around at an NT 4.0 machine for a while, searching for the printer name and was not able to come up with anything terribly useful. It all seems mapped to some kind of WinSpool,Nexx kind of affair, but then the tracks seem to fade away.
Article ID:   W13690
Filename:   Determine default printer NT.txt
File Created: 2001:01:03:13:37:20
Last Updated: 2001:01:03:13:37:20