how can i exclude printers from my batch file
Moderator: DosItHelp
-
- Posts: 32
- Joined: 07 Sep 2012 03:50
Re: how can i exclude printers from my batch file
no sorry it doesnt work. the list is still the same and when i choose an printer it gives me an error loop to fast to read.
Re: how can i exclude printers from my batch file
ok, foxidrive was right i didn't understand what he said till i tested it, we should first get the printerlist, modify it, then display what is in that file and then choose the printer, i will post the code in few minutes.
Last edited by abc0502 on 13 Sep 2012 05:32, edited 1 time in total.
-
- Posts: 32
- Joined: 07 Sep 2012 03:50
Re: how can i exclude printers from my batch file
you're to kind! really helpful and lots of patience.
i will thank you for that!
i wan't to learn this so badly but it aint easy if its new for you!
i will thank you for that!
i wan't to learn this so badly but it aint easy if its new for you!
Re: how can i exclude printers from my batch file
try it now , i changed the order of the commands but all command the same
if you want the old order i can post it to you or pm you with it
Code: Select all
@echo off
:: generate Vbscript and call it to get the printer list, then delete it
set "vbsscript=printerlist.vbs"
Call :vb
cscript /nologo "%vbsscript%" >printerlist.txt
Del /F /S /Q "%vbsscript%" >nul
:: now we remove unwanted printers and fix the number order
setlocal enabledelayedexpansion
:: This will delete un-wanted printers
ren "printerlist.txt" "printerlist.tmp"
set c=0
for /F "tokens=*" %%A in ('type "printerlist.tmp"') Do (
set /a c+=1
IF not !c!==1 (
IF not !c!==3 (
IF not !c!==6 (
echo %%A>>"printerlist_2.tmp" )))
)
:: This will fix printer numbers
set c=0
for /F "tokens=1,* delims=)" %%A in ('type "printerlist_2.tmp"') Do (
set /a c+=1
echo !c!^) %%B>>"printerlist.txt"
)
Endlocal
:: delete temp files
Del /F /S /Q "printerlist.tmp" >nul
Del /F /S /Q "printerlist_2.tmp" >nul
:: now display the new printer list after modification, so the user get to choose
type printerlist.txt
echo.
:loop
set "in="
set /p "in=Type the printer number (or just ENTER to quit): "
if not defined IN (
del printerlist.txt
goto :EOF
)
:: set the default printer
for /f "tokens=1,*" %%a in ('findstr /r "^%in%)" ^< "printerlist.txt"') do set "printer=%%b"
echo.
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%printer%"
echo Default Printer is now "%printer%"
pause
Exit /B
:vb
> "%vbsscript%" echo strComputer = "."
>> "%vbsscript%" echo Set objWMIService = GetObject("winmgmts:" ^& "{impersonationLevel=impersonate}!\\" ^& strComputer ^& "\root\cimv2")
>> "%vbsscript%" echo Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
>> "%vbsscript%" echo num=1
>> "%vbsscript%" echo For Each objPrinter in colInstalledPrinters
>> "%vbsscript%" echo Wscript.Echo num ^& ") " ^& objPrinter.Name
>> "%vbsscript%" echo num = num + 1
>> "%vbsscript%" echo Next
if you want the old order i can post it to you or pm you with it
Re: how can i exclude printers from my batch file
Your code will break when you add new printers, or use it on another machine.
-
- Posts: 32
- Joined: 07 Sep 2012 03:50
Re: how can i exclude printers from my batch file
dude you are wonderfull! it works! thanks so much man, you guys really know how to help people. kudo's for you!
i will throw this script into my full one and let you know how that turns out!
i will throw this script into my full one and let you know how that turns out!
Re: how can i exclude printers from my batch file
bramsharon wrote:dude you are wonderfull! it works! thanks so much man, you guys really know how to help people. kudo's for you!
i will throw this script into my full one and let you know how that turns out!
you better consider Foxidrive note
Foxidrive wrote:Your code will break when you add new printers, or use it on another machine.
-
- Posts: 32
- Joined: 07 Sep 2012 03:50
Re: how can i exclude printers from my batch file
darn it, i think you guys helped me enough, i am very pleased on how you guys helped me out. i think i just talk with my boss that its best to just keep that list. its not that it gets much more crowed because of that. perhaps he thinks its okay this way.
thanks a lot people! you guys helped me out alot!
thanks a lot people! you guys helped me out alot!
Re: how can i exclude printers from my batch file
It seems that the printers aren't in alphabetic order, and not even in order of installation. The fax driver in mine should be a default on installation and here it is listed last.
1) Snagit 10
2) Samsung ML-1740 Series
3) Microsoft XPS Document Writer
4) Fax
So it is entirely machine dependent.
1) Snagit 10
2) Samsung ML-1740 Series
3) Microsoft XPS Document Writer
4) Fax
So it is entirely machine dependent.
Re: how can i exclude printers from my batch file
yes just as you said, but in any way you always choose the printer you want to be the default so there is no need to remove these 3 printers, just get the list and then select the one you want
-
- Posts: 32
- Joined: 07 Sep 2012 03:50
Re: how can i exclude printers from my batch file
yes i will leave it that way, it works to but my boss would like it more if those printers were 'invincible' but i already thought that would be an impossible job.
thanks again guys! you were very helpfull and patient!
thanks again guys! you were very helpfull and patient!
Re: how can i exclude printers from my batch file
Here is a fix for the problem, we won't use line number but will use the names of the 3 printers
Instead of this code:
we use this
Code: Select all
@echo off
:: generate Vbscript and call it to get the printer list, then delete it
set "vbsscript=printerlist.vbs"
Call :vb
cscript /nologo "%vbsscript%" >printerlist.txt
Del /F /S /Q "%vbsscript%" >nul
:: now we remove unwanted printers and fix the number order
setlocal enabledelayedexpansion
:: This will delete un-wanted printers
ren "printerlist.txt" "printerlist.tmp"
For /F "tokens=*" %%a in ('find /I /v "OneNote" ^<"printerlist.tmp"') Do echo %%a>>"temp1.txt"
For /F "tokens=*" %%a in ('find /I /v "Fax" ^<"temp1.txt"') Do echo %%a>>"temp2.txt"
For /F "tokens=*" %%a in ('find /I /v "Writer" ^<"temp2.txt"') Do echo %%a>>"printerlist_2.tmp"
:: This will fix printer numbers
set c=0
for /F "tokens=1,* delims=)" %%A in ('type "printerlist_2.tmp"') Do (
set /a c+=1
echo !c!^) %%B>>"printerlist.txt"
)
Endlocal
:: delete temp files
Del /F /S /Q "printerlist.tmp" >nul
Del /F /S /Q "printerlist_2.tmp" >nul
Del /F /S /Q "temp1.txt" >nul
Del /F /S /Q "temp2.txt" >nul
:: now display the new printer list after modification, so the user get to choose
type printerlist.txt
echo.
:loop
set "in="
set /p "in=Type the printer number (or just ENTER to quit): "
if not defined IN (
del printerlist.txt
goto :EOF
)
:: set the default printer
for /f "tokens=1,*" %%a in ('findstr /r "^%in%)" ^< "printerlist.txt"') do set "printer=%%b"
echo.
RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "%printer%"
echo Default Printer is now "%printer%"
pause
Exit /B
:vb
> "%vbsscript%" echo strComputer = "."
>> "%vbsscript%" echo Set objWMIService = GetObject("winmgmts:" ^& "{impersonationLevel=impersonate}!\\" ^& strComputer ^& "\root\cimv2")
>> "%vbsscript%" echo Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
>> "%vbsscript%" echo num=1
>> "%vbsscript%" echo For Each objPrinter in colInstalledPrinters
>> "%vbsscript%" echo Wscript.Echo num ^& ") " ^& objPrinter.Name
>> "%vbsscript%" echo num = num + 1
>> "%vbsscript%" echo Next
Instead of this code:
Code: Select all
set c=0
for /F "tokens=*" %%A in ('type "printerlist.tmp"') Do (
set /a c+=1
IF not !c!==1 (
IF not !c!==3 (
IF not !c!==6 (
echo %%A>>"printerlist_2.tmp" )))
)
we use this
Code: Select all
For /F "tokens=*" %%a in ('find /I /v "OneNote" ^<"printerlist.tmp"') Do echo %%a>>"temp1.txt"
For /F "tokens=*" %%a in ('find /I /v "Fax" ^<"temp1.txt"') Do echo %%a>>"temp2.txt"
For /F "tokens=*" %%a in ('find /I /v "Writer" ^<"temp2.txt"') Do echo %%a>>"printerlist_2.tmp"
-
- Posts: 32
- Joined: 07 Sep 2012 03:50
Re: how can i exclude printers from my batch file
sorry to say but it aint fixed, but its fine i'll deal it with my boss it will be fine was just curious if it was possible, i don't want to make a new script for every pc as whe have 400 pc's
Re: how can i exclude printers from my batch file
are you sure, i tested on Foxidrive printer list, billrich list and your list and it always get the printerlist.txt file with the 3 printers removed and numbers fixed.
Re: how can i exclude printers from my batch file
It works here.