Re: batch file to install printer

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance




I ran into this same problem, and I decided to stick with batch until i
have time to revise it with more logic in VBS.

I have 70 wan sites and one central server location. Need printers
installed via tcp/ip port instead of via print server. We can't afford
70 print servers 70 sites, and site speed is a critical issue.

I needed install to all printers at each location to each machine at
same location on a per machine basis, not per user. This runs as a
startup script via GPO linked to site OU in Active Directory. So it
runs every time machine starts up. To avoid repeated installs of all
printers at site, a text file is written after the printer is installed
in the c:\temp folder as the same name that is used for the printport
and printername. There is an IF NOT EXIST check before it installs the
printer looking for that txt file. It needs an error level check to
make it better but works without it. To speed it up, i copy all
needed drivers to one machine at each location in a wide open shared
folder, and map the driver path to that site's PRINTERDRIVERS folder.

there is also a delete loop that can be used at the bottom to remove
the same type of machine level printer installs.

this is long, i included my whole template file which makes it easy to
update for each site. you only need to change the P# variable values at
the top which is used to name the TCP/IP port, the printer, and the text
file. at each install section further down you need to enter the IP
address for the Port being created, open the driver.inf file and copy
the full name of the printer as will be shown in the driver list, and
then the path to the driver itself. The variables and 10 loop template
make it very easy to adapt per site, then just delete the uneeded loops.
remember "::" comments out a line, delete to activate it.

This is honestly spaghetti code. but it works, so who cares? I can
spend 10 minutes to adapt this to each site, slap together a very simple
GPO for it, and let them restart in their own time, and voila. much
easier than installing anywhere from 1-10 printers on 1300 machines
remotely. SO ROCK ON SPAGHETTI CODE! i'll post any revisions that
clean it up.

oh yeah, to make this run without interruption, you'll need an
additional GPO that does one other thing (needs to be separate and apply
before each startup script GPO) that is set the unsigned driver feature
to always allow. that is found at
ComputerConfiguration/WindowsSettings/SecuritySettings/LocalPolicies/SecurityOptions/Devices:
Unsigned Driver installation behavior. Set it to Silently Succeed.

This will take a few minutes on initial run, but the logic loop at the
top makes it run very fast on subsequent runs. I'm sure there is a
better and simpler way to do all this (vbs) but no one has posted how to
do it, so the mother of all invention, necessity, created this. I hope
it helps someone else. If you know of a better way to do this, POST
IT! Most other solutions i found are centered around print servers and
I know there are others like me which doesn't work for.

here you go, copy and paste in a txt file, and rename it to *.bat
type...


SET P1=%PRINTER1 (can be descriptive names for each but no spaces)
SET P2=%PRINTER2
SET P3=%PRINTER3
SET P4=%PRINTER4
SET P5=%PRINTER5
SET P6=%PRINTER6
SET P7=%PRINTER7
SET P8=%PRINTER8
SET P9=%PRINTER9
SET P10=%PRINTER10
:LOOP1
IF NOT EXIST C:\TEMP\%P1%.TXT GOTO :I1
IF NOT EXIST C:\TEMP\%P2%.TXT GOTO :I2
IF NOT EXIST C:\TEMP\%P3%.TXT GOTO :I3
IF NOT EXIST C:\TEMP\%P4%.TXT GOTO :I4
IF NOT EXIST C:\TEMP\%P5%.TXT GOTO :I5
IF NOT EXIST C:\TEMP\%P6%.TXT GOTO :I6
IF NOT EXIST C:\TEMP\%P7%.TXT GOTO :I7
IF NOT EXIST C:\TEMP\%P8%.TXT GOTO :I8
IF NOT EXIST C:\TEMP\%P9%.TXT GOTO :I9
IF NOT EXIST C:\TEMP\%P10%.TXT GOTO :I10
::GOTO :DELETELOOP ::USE TO WITH END SECTION TO DELETE MACHINE LEVEL
PRINTER INSTALLATIONS, UNCOMMENT TO USE
GOTO :EOF

:I1
::SET P1=%printer & port name with no quotes
SET PIP1=%1(ip address with an extra 1 in front of it with no quotes)
SET PNAME1=%"printer name from inf file IN QUOTES"
SET PDRIVER1=%"driver file path IN QUOTES"
cscript.exe c:\windows\system32\prnport.vbs -a -r %P1% -h %PIP1% -o raw
-n 9100
rundll32 printui.dll PrintUIEntry /if /b %P1% /f %PDRIVER1% /r %P1% /m
%PNAME1% /z
P1 > C:\TEMP\%P1%.TXT
GOTO :LOOP1
:I2
::SET P2=%printer & port name with no quotes
SET PIP2=%1(ip address with an extra 1 in front of it with no quotes)
SET PNAME2=%"printer name from inf file IN QUOTES"
SET PDRIVER2=%"driver file path IN QUOTES"
cscript.exe c:\windows\system32\prnport.vbs -a -r %P2% -h %PIP2% -o raw
-n 9100
rundll32 printui.dll PrintUIEntry /if /b %P2% /f %PDRIVER2% /r %P2% /m
%PNAME2% /z
P2 > C:\TEMP\%P2%.TXT
GOTO :LOOP1
:I3
::SET P3=%printer & port name with no quotes
SET PIP3=%1(ip address with an extra 1 in front of it with no quotes)
SET PNAME3=%"printer name from inf file IN QUOTES"
SET PDRIVER3=%"driver file path IN QUOTES"
cscript.exe c:\windows\system32\prnport.vbs -a -r %P3% -h %PIP3% -o raw
-n 9100
rundll32 printui.dll PrintUIEntry /if /b %P3% /f %PDRIVER3% /r %P3% /m
%PNAME3% /z
P3 > C:\TEMP\%P3%.TXT
GOTO :LOOP1
:I4
::SET P4=%printer & port name with no quotes
SET PIP4=%1(ip address with an extra 1 in front of it with no quotes)
SET PNAME4=%"printer name from inf file IN QUOTES"
SET PDRIVER4=%"driver file path IN QUOTES"
cscript.exe c:\windows\system32\prnport.vbs -a -r %P4% -h %PIP4% -o raw
-n 9100
rundll32 printui.dll PrintUIEntry /if /b %P4% /f %PDRIVER4% /r %P4% /m
%PNAME4% /z
P4 > C:\TEMP\%P4%.TXT
GOTO :LOOP1
:I5
::SET P5=%printer & port name with no quotes
SET PIP5=%1(ip address with an extra 1 in front of it with no quotes)
SET PNAME5=%"printer name from inf file IN QUOTES"
SET PDRIVER5=%"driver file path IN QUOTES"
cscript.exe c:\windows\system32\prnport.vbs -a -r %P5% -h %PIP5% -o raw
-n 9100
rundll32 printui.dll PrintUIEntry /if /b %P5% /f %PDRIVER5% /r %P5% /m
%PNAME5% /z
P5 > C:\TEMP\%P5%.TXT
GOTO :LOOP1
:I6
::SET P6=%printer & port name with no quotes
SET PIP6=%1170.94.212.115
SET PNAME6=%"printer name from inf file IN QUOTES"
SET PDRIVER6=%"driver file path IN QUOTES"
cscript.exe c:\windows\system32\prnport.vbs -a -r %P6% -h %PIP6% -o raw
-n 9100
rundll32 printui.dll PrintUIEntry /if /b %P6% /f %PDRIVER6% /r %P6% /m
%PNAME6% /z
P6 > C:\TEMP\%P6%.TXT
GOTO :LOOP1

:I7
::SET P7=%printer & port name with no quotes
SET PIP7=%1(ip address with an extra 1 in front of it with no quotes)
SET PNAME7=%"printer name from inf file IN QUOTES"
SET PDRIVER7=%"driver file path IN QUOTES"
cscript.exe c:\windows\system32\prnport.vbs -a -r %P7% -h %PIP7% -o raw
-n 9100
rundll32 printui.dll PrintUIEntry /if /b %P7% /f %PDRIVER7% /r %P7% /m
%PNAME7% /z
P7 > C:\TEMP\%P7%.TXT
GOTO :LOOP1

:I8
::SET P8=%printer & port name with no quotes
SET PIP8=%1(ip address with an extra 1 in front of it with no quotes)
SET PNAME8=%"printer name from inf file IN QUOTES"
SET PDRIVER8=%"driver file path IN QUOTES"
cscript.exe c:\windows\system32\prnport.vbs -a -r %P8% -h %PIP8% -o raw
-n 9100
rundll32 printui.dll PrintUIEntry /if /b %P8% /f %PDRIVER8% /r %P8% /m
%PNAME8% /z
P8 > C:\TEMP\%P8%.TXT
GOTO :LOOP1

:I9
::SET P9=%printer & port name with no quotes
SET PIP9=%1(ip address with an extra 1 in front of it with no quotes)
SET PNAME9=%"printer name from inf file IN QUOTES"
SET PDRIVER9=%"driver file path IN QUOTES"
cscript.exe c:\windows\system32\prnport.vbs -a -r %P9% -h %PIP9% -o raw
-n 9100
rundll32 printui.dll PrintUIEntry /if /b %P9% /f %PDRIVER9% /r %P9% /m
%PNAME9% /z
P9 > C:\TEMP\%P9%.TXT
GOTO :LOOP1

:I10
::SET P10=%printer & port name with no quotes
SET PIP10=%1(ip address with an extra 1 in front of it with no quotes)
SET PNAME10=%"printer name from inf file IN QUOTES"
SET PDRIVER10=%"driver file path IN QUOTES"
cscript.exe c:\windows\system32\prnport.vbs -a -r %P10% -h %PIP10% -o
raw -n 9100
rundll32 printui.dll PrintUIEntry /if /b %P10% /f %PDRIVER10% /r %P10%
/m %PNAME10% /z
P10 > C:\TEMP\%P10%.TXT
GOTO :LOOP1






:DELETELOOP

::TO DELETE OLD/UNUSED PRINTER INSTALLS AND PORTS FROM COMPUTER
::DEFINE D1 WITH OLD PRINTER PORT NAME (P#)

::SET D1=%
::IF EXIST C:\TEMP\%D1%.TXT rundll32 printui.dll,PrintUIEntry /dl /n
%D1% /q
::IF EXIST C:\TEMP\%D1%.TXT cscript.exe c:\windows\system32\prnport.vbs
-d -r %D1%
::ECHO Y | DEL C:\TEMP\%D1%.TXT
::GOTO :EOF


--
MattLieblong
------------------------------------------------------------------------
MattLieblong's Profile: http://forums.techarena.in/members/mattlieblong.htm
View this thread: http://forums.techarena.in/xp-print-fax/937795.htm

http://forums.techarena.in

.



Relevant Pages

  • Re: what s for
    ... goto:end ... Then the quotes aren't required - though this assumes only one ... On the other hand when one's uses right clic sendto  to the batch 'sendto' ... In addition, expansion of batch script argument references (%0, %1, ...
    (microsoft.public.win2000.cmdprompt.admin)
  • Re: What do you think about the code?
    ... of a modular design with strict avoidance of goto, ... function that has outgrown its readability. ... the whole switch because I don't care if I'm in quotes when checking for the ... the test for quotes explicitly where required. ...
    (comp.lang.c)
  • Re: Outlook Express Address Book
    ... Search files and folders for "*.wab" without the quotes. ... PRINT "Windows XP ERROR" ... GOTO 1 ...
    (alt.os.windows-xp)
  • Re: basic help to run an application from WSH
    ... string values must be enclosed in quotes. ... The Run method will execute on c:\notepad.exe. ... I'm just learning vbscript for wsh and here is my first script, ... Also if I cut and paste the exact file path from the script into the ...
    (microsoft.public.scripting.vbscript)
  • RE: Unable to start scheduled task after creating it with Schtasks
    ... Turns out the problem was the quotes were being stripped off the file path in ... No big deal, just need to escape the quotes out, well, not ... I'm using Schtasks to create a scheduled task on a remote server using the ...
    (microsoft.public.windows.server.general)