Windows Printer Settings
From QB64 Wiki
I have found that these WMI SHELL commands work in Windows XP, 7 and 8.1. So with a bit of coding, one can identify the printers associated with a user's PC including the default, allow the user to pick any printer for output from within the given application, change that printer to the current default for LPRINT output, and when the user exits the application then change the default back to the original printer.
This piece of code issues the command to display a PC's list of printers and routes the output to a text file...
SHELL _HIDE "CMD /C wmic printer get name,default > defaultprinter.txt" 'copy list of available printers to a text file
- Note: WMI commands will only work in Windows XP and newer operating systems.
The contents of the resulting file is as follows...the default printer is listed as "TRUE":
Default Name FALSE Microsoft XPS Document Writer TRUE HP Photosmart C7200 series FALSE HP Officejet Pro 8600 FALSE Fax
By parsing the text in the file, we can find alternative printer names, convert them to text variable names and swap them in other WMI commands.
Here is the code to set the default printer to the "HP Officejet Pro 8600"...
SHELL _HIDE "CMD /C wmic printer where name='HP Officejet Pro 8600' call setdefaultprinter" 'set default printer
After executing the above code, and then running the first code line again, we see the following contents of the text file:
Default Name FALSE Microsoft XPS Document Writer FALSE HP Photosmart C7200 series TRUE HP Officejet Pro 8600 FALSE Fax