A console program to test if a printer's duplex mode is set to on
can be called by another program and a returned value given without displaying the results
program returns a error level of 1 if duplex printing is turned on
the program should be flexible for all purposes.
Any printer named "fax" will be skipped automatically
Great for batch files!
This program was designed so that early detection of printers that can print in duplex and have the dulpex setting turned on does not make a mess of things if these printers are chosen to print with. Batch files or other programs that can run this program and look for a returned errorlevel to check a printers duplex setting.
I guess i should of placed code in there for checking the default printer, oh well, on next set of code i am sure.
added code should now handle all fax printers correctly( meaning do not get information from them) except where the fax printer is the default printer and there is two or more printers and when the program is asked to get the duplex setting specifically of the default printer.
can be called by another program and a returned value given without displaying the results
program returns a error level of 1 if duplex printing is turned on
the program should be flexible for all purposes.
Any printer named "fax" will be skipped automatically
Great for batch files!
This program was designed so that early detection of printers that can print in duplex and have the dulpex setting turned on does not make a mess of things if these printers are chosen to print with. Batch files or other programs that can run this program and look for a returned errorlevel to check a printers duplex setting.
I guess i should of placed code in there for checking the default printer, oh well, on next set of code i am sure.
added code should now handle all fax printers correctly( meaning do not get information from them) except where the fax printer is the default printer and there is two or more printers and when the program is asked to get the duplex setting specifically of the default printer.
Code:
#COMPILE EXE FUNCTION PBMAIN () AS LONG LOCAL a$ LOCAL i&,j&,k& LOCAL ix AS LONG, sPrinters AS STRING,sprinter AS STRING LOCAL temp$ LOCAL quiet& LOCAL pause& temp$=" "+UCASE$(COMMAND$)+" " IF TRIM$(temp$)="/HELP" OR TRIM$(temp$)="?" OR TRIM$(temp$)="/?" THEN STDOUT "command tail options to this program" STDOUT "/quiet = do not display results, just return a errorlevel of 1(one)" STDOUT " if there are any printers with the duplex mode set on." STDOUT "/pause = pause after results are displayed if quiet is not chosen" STDOUT "/allprinters = check all printers" STDOUT "/default = check just the default printer" STDOUT "no printers on command tail means all printers will be checked" STDOUT "specfic printers only need to be on the command line" STDOUT "any printer name with "+$DQ+" fax "+$DQ+" in it will be skipped" STDOUT "ex options: HP LaserJet /pause" STDOUT " HP LaserJet /quiet" STDOUT " /allprinters /pause" STDOUT " /pause" STDOUT " /quiet" STDOUT "errorlevel 1(one) will be returned if printers duplex setting is on" STDOUT "press any key to continue" WAITKEY$ EXIT FUNCTION END IF IF PRINTERCOUNT=0& THEN EXIT FUNCTION J&=0& j&=INSTR(temp$," /QUIET ") IF J& THEN quiet&=1&:REPLACE " /QUIET " WITH "" IN TEMP$:TEMP$=" "+TRIM$(TEMP$)+" " j&=INSTR(temp$," /PAUSE ") IF J& THEN pause&=1&:REPLACE " /PAUSE " WITH "" IN TEMP$:TEMP$=" "+TRIM$(TEMP$)+" " IF TRIM$(TEMP$)="" THEN TEMP$=" /ALLPRINTERS " i&=0 'returned errorlevel k&=0 'flag for setting if any printers have the duplex setting on IF INSTR(temp$," /DEFAULT ") THEN j&=0& 'set j to zero, being used as a duplex mode flag IF PRINTERCOUNT=1& THEN sprinter=TRIM$(PRINTER$(NAME,1&)) IF INSTR(" "+UCASE$(sprinter)+" "," FAX ") THEN EXIT FUNCTION END IF XPRINT ATTACH DEFAULT sprinter=XPRINT$ IF sprinter="" THEN XPRINT CLOSE:EXIT FUNCTION IF INSTR(" "+UCASE$(sprinter)+" "," FAX ") THEN XPRINT CANCEL XPRINT CLOSE EXIT FUNCTION END IF XPRINT GET DUPLEX TO j& IF j&>1& THEN INCR K&:sprinters=sprinters+$CRLF+sprinter XPRINT CANCEL XPRINT CLOSE GOTO reportresults END IF FOR ix = 1 TO PRINTERCOUNT j&=0& 'set j to zero, being used as a duplex mode flag sprinter=TRIM$(PRINTER$(NAME,ix)) IF INSTR(" "+UCASE$(sprinter)+" "," FAX ") THEN ITERATE FOR IF INSTR(temp$," /ALLPRINTERS ")=0 THEN IF INSTR(temp$," "+UCASE$(sprinter)+" ")=0 THEN ITERATE FOR END IF XPRINT ATTACH sprinter XPRINT GET DUPLEX TO j& XPRINT CANCEL XPRINT CLOSE 'When j& <2 then the duplex mode should be set to off on most printers IF j&>1& THEN INCR K&:sprinters=sprinters+$CRLF+sprinter NEXT reportresults: IF k&>0 THEN IF quiet&=0 THEN sprinters="Printer(s) with duplex mode set to on."+sprinters STDOUT sprinters IF pause&=1 THEN STDOUT $CRLF+"press any key to continue":WAITKEY$ END IF i&=1& 'errorlevel 1 is returned, found a printer with a duplex setting on END IF FUNCTION=i& END FUNCTION