10/6/2023 0 Comments Printer selection![]() so that the Name line from the report is skipped. Omitting this selects ALL.įirst step is to add the skip=1 to the for /f. IF DEFINED printfilter ECHO %%F|FIND /i "%printfilter%" >nul&IF ERRORLEVEL 1 SET /a printercnt-=1įor /l %%N in (1 1 %printerCnt%) do SET "choices=!choices!%%N"&SET "printer%%N=!printer%%N:~0,-1!"&IF %printercnt% gtr 1 echo %%N - !printer%%N!ĮCHO RUNDL元2 PRINTUI.DLL,PrintUIEntry /y /n "%str%"ĮCHO RUNDL元2 PRINTUI.DLL,PrintUIEntry /y /n "%DefaultPrinter%"įirst, to specify the filter, simply append an appropriate string (PDF, XPS, OneNote) to the batchname as a parameter. REM We create a file to filter with each word like XPS,OneNote and PDFįor /l %%N in (1 1 %printerCnt%) do echo - Įcho =įor /f "skip=1eol=: delims=" %%F in ('wmic printer get Name') do ( REM We Ignore printer begin with Micro or Fax in the name Title Filter results in batch script for user printer selection This also removes the phantom "blank" line (actually a ) and in this case you don't need to use the Trim function ! off The trailing can be removed by passing the value through another FOR /F loop. ![]() If Exist "%FilterListLong%" Del "%FilterListLong%" If Exist "%FilterList%" Del "%FilterList%" RUNDL元2 PRINTUI.DLL,PrintUIEntry /y /n "%NewPrinter%" This window will close automatically in 10 seconds. This window will close automatically in 30 seconds.ĮCHO Printer selected: !printer%selection%!Įcho. IF %selection% gtr %printercnt% GOTO :EOFĮcho. IF %choices%=1 SET /a selection=1&GOTO autoselectĬhoice /c %choices% /m "Enter a printer number: " 'wmic printer get Name ^|findstr /G:%FilterListLong%"'įor /l %%N in (1 1 %printerCnt%) do SET "choices=!choices!%%N"&SET "printer%%N=!printer%%N!"&IF %printercnt% gtr 1 echo %%N - !printer%%N! REM Create a file to filter with each word like XPS,OneNote and PDF Set "FilterListLong=%Temp%\FilterListLong.txt" ::If no printers have been found, go to filterlistlong 'wmic printer get Name ^|findstr /G:%FilterList%"' REM Create a file to filter just for PDF printers There is probably a more elegant way to write this code but I am new to this so laid it out as I understood it. This was based on the answer provided by and I incorporated elements provided by also. I have included the code I ended up using. RUNDL元2 PRINTUI.DLL,PrintUIEntry /y /n "%DefaultPrinter%" RUNDL元2 PRINTUI.DLL,PrintUIEntry /y /n "%str%" 'wmic printer where "default=True" get name /value'ĮCHO =ĮCHO Processing locally installed printersįor /f "eol=: delims=" %%F in ('wmic printer get Name') do (įor /l %%N in (1 1 %printerCnt%) do echo %%N - !printer%%N! I would like to filter the list of printers the user is shown to just ones from the appropriate list (e.g. I have managed to incorporate elements of many different examples to get to the stage where the script is functioning, although it is creating an extra entry at the start and end of the list. MessageBox.I am trying to create a script to allow users to temporarily set the default windows printer to a selected printer (PDF, XPS, OneNote) before printing and then automatically set the default back to the original printer after a specified time. Shell(String.Format("rundll32 printui.dll,PrintUIEntry /y /n """) 'Display current default printer on combobox textsĬomboBox1.Text = įunction to set a printer as default: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ![]() 'display installed printer into combobox list itemįor Each strInstalledPrinters In PrinterSettings.InstalledPrintersĬ(strInstalledPrinters) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Here's the code I have so far (one ComboBox and one Button) Imports So it would only show printer1ABC and network1 abc? Is there a way I can only show Printers names that contain specific text? The code shows all installed printers in a ComboBox and the submit Button will set the Printer selected in the ComboBox as the default printer for that user. I've made a program that will run on startup asking the users to select their default printer.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |