Difference between revisions of "Windows Printer Settings"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>SMcNeill
(transfers the contents of duplicate page "Printing to different printers" to this one.)
Line 1: Line 1:
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.
There are some '''Windows "command line" statements''' that allow one to 1) identify the current Windows default printer (as well as other printers associated with a PC) and 2) then change the default to a different printer. And one can then issue "SHELL" statements in QB64 to execute those command statements.  See the following examples by member '''DonW''':


<center>'''Explanation and code by DonW'''</center>
This code issues the command to display a PC's list of printers and routes the output to a text file...
 
{{CodeStart}}{{Cl|SHELL}} {{Cl|_HIDE}} "CMD /C" + "wmic printer get name,default > default.txt"
 
This piece of code issues the command to display a PC's list of printers and routes the output to a text file...
{{CodeStart}} '' ''
{{Cl|SHELL}} _HIDE "CMD /C wmic printer get name,default > defaultprinter.txt" 'copy list of available printers to a text file
{{CodeEnd}}
{{CodeEnd}}
: ''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":
The contents of the resulting file (from one of my PC's) is as follows...the default printer is listed as "TRUE":
{{TextStart}} Default  Name                           
{{TextStart}}Default  Name                           
   FALSE    Microsoft XPS Document Writer
   FALSE    Microsoft XPS Document Writer  
   TRUE    HP Photosmart C7200 series     
   TRUE    HP Photosmart C7200 series     
   FALSE    HP Officejet Pro 8600        
   FALSE    HP Officejet Pro 8600        
   FALSE    Fax
   FALSE    Fax
{{TextEnd}}
{{TextEnd}}
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"...
Here is the code to set the default printer to the "HP Officejet Pro 8600"...
{{CodeStart}} '' ''
{{Cl|SHELL}} _HIDE "CMD /C wmic printer where name='HP Officejet Pro 8600' call setdefaultprinter" 'set default printer
{{CodeEnd}}


{{CodeStart}}{{Cl|SHELL}} {{Cl|_HIDE}} "CMD /C" + "wmic printer where name='HP Officejet Pro 8600' call setdefaultprinter" {{CodeEnd}}


After executing the above code, and then running the first code line again, we see the following contents of the text file:
Then running the get Default [[SHELL]] code again, we see the following contents of the text file:
{{TextStart}}
{{TextStart}}Default  Name                           
  Default  Name                           
   FALSE    Microsoft XPS Document Writer  
   FALSE    Microsoft XPS Document Writer
   FALSE    HP Photosmart C7200 series     
   FALSE    HP Photosmart C7200 series     
   TRUE    HP Officejet Pro 8600        
   TRUE    HP Officejet Pro 8600        
   FALSE    Fax
   FALSE    Fax
{{TextEnd}}
{{TextEnd}}
Now we see that the "HP Officejet Pro 8600" is marked "TRUE", and thus is now the default printer for [[LPRINT]] or [[_PRINTIMAGE]].
 
Now we see that the "HP Officejet Pro 8600" is marked "TRUE", and thus is now the default printer for [[LPRINT]].
 
These SHELL commands work in Windows XP, 7, 8.1 and 10.




{{PageSeeAlso}}
{{PageSeeAlso}}
* [[SHELL]]
* [[SHELL]], [[_HIDE]]
* [[LPRINT]]
* [[LPRINT]]
*[[_PRINTIMAGE]]
 
 
===External Links===
* [http://www.computerhope.com/wmic.htm Windows WMI commands]
* [http://www.computerhope.com/wmic.htm Windows WMI commands]
* [http://www.cups.org/documentation.php/options.html Linux Printer Commands]
* [http://www.cups.org/documentation.php/options.html Linux Printer Commands]

Revision as of 17:17, 14 October 2017

There are some Windows "command line" statements that allow one to 1) identify the current Windows default printer (as well as other printers associated with a PC) and 2) then change the default to a different printer. And one can then issue "SHELL" statements in QB64 to execute those command statements. See the following examples by member DonW:

This 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 > default.txt"

The contents of the resulting file (from one of my PC's) 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

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"

Then running the get Default SHELL code 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

Now we see that the "HP Officejet Pro 8600" is marked "TRUE", and thus is now the default printer for LPRINT.

These SHELL commands work in Windows XP, 7, 8.1 and 10.


See also


External Links



Navigation:
Keyword Reference - Alphabetical
Keyword Reference - By Usage
Main Wiki Page