Go Back   TechArena Community > Technical Support > Computer Help > Windows XP > XP Print Fax
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags:

batch file to install printer

XP Print Fax


Reply
 
Thread Tools Search this Thread
  #1  
Old 24-03-2008
Steve Cummings
 
Posts: n/a
batch file to install printer

Hi -
I work for a non profit organization and we are trying to find a way to run
a Batch File that Installs a Local TCP/IP Printer with a specific IP address
with NO user interaction.
I have code that works for a BATCH file but it has to be run as a local
administrator. I am trying to have this batch file run as a login script on
our network to a bunch of laptop users on our domain.

Here is what I have -

-----------
cd c:\windows\system32
cscript prnport.vbs -a -r IP_192.168.1.115 -h 192.168.1.115 -o raw -n 9100
cscript prnmngr.vbs -a -p "Xerox Printer" -m "Xerox 4510" -r
"IP_192.168.1.115"
pause

------------

Ive tried this using a Run-As with the same code from above - but that
requires entering in a Password and we need this done automattically.
Also - the 2nd command does not work using Run as but the First command
does - i find that strange as well.

------------
cd c:\windows\system32
runas /profile /user:Domain\Account "cscript prnport.vbs -a -r
IP_192.168.1.115 -h 192.168.1.115 -o raw -n 9100"
runas /profile /user:Domain\Account "cscript prnmngr.vbs -a -p "Xerox
Printer" -m "Xerox 4510" -r "IP_192.168.1.115""
pause
-------------


If you can assist with another way of doing this or a way of doing this
using the same code would be really helpful.
I've done alot of research online and there seems to be no real way of doing
this.
I have tried many 3rd party applications that is suppposed to make this work
easily but I have not had any luck with getting it to work.

Let me know.

Thanks,
Steve





Reply With Quote
  #2  
Old 24-03-2008
Linn Kubler
 
Posts: n/a
Re: batch file to install printer

Hi Steve,

Finally, a question I can offer some help on. I'm curious though, why you
want to add a printer in a logon script, wouldn't that re-add the printer
each time the user logs on to the computer?

What I do is add the network printer globally to the workstation. Then it
is available for all users. Here is a helpful site that discusses this
option:

http://members.shaw.ca/bsanders/NetPrinterAllUsers.htm

Here is a sample script I use for remotely installing a printer on a
computer. The computer must be running but does not need to have the local
administrator logged in. However, you do need to run the script as a user
who has administrative rights on the remote computer. In my case I run this
script logged in as the domain administrator and pass the name of the remote
computer as a parameter.

My script has two lines:
rundll32 printui.dll, PrintUIEntry /ga /n\\cmw-exch\CLAIMS /c\\%1
pause

If I call this script, remote_claims_printer_install.cmd, I would run it
like this, from the command prompt:

c:\>remote_claims_pritner_install.cmd comp1

To make the printer available to the end user you have to restart the print
spooler, but a reboot will handle that if you can wait. Otherwise there's a
couple of ways to remotely restart a service.

Hope that all helps,
Linn

"Steve Cummings" <scummings@ahrc.org> wrote in message
news:%23SCsUHcjIHA.5084@TK2MSFTNGP04.phx.gbl...
> Hi -
> I work for a non profit organization and we are trying to find a way to
> run a Batch File that Installs a Local TCP/IP Printer with a specific IP
> address with NO user interaction.
> I have code that works for a BATCH file but it has to be run as a local
> administrator. I am trying to have this batch file run as a login script
> on our network to a bunch of laptop users on our domain.
>
> Here is what I have -
>
> -----------
> cd c:\windows\system32
> cscript prnport.vbs -a -r IP_192.168.1.115 -h 192.168.1.115 -o raw -n 9100
> cscript prnmngr.vbs -a -p "Xerox Printer" -m "Xerox 4510" -r
> "IP_192.168.1.115"
> pause
>
> ------------
>
> Ive tried this using a Run-As with the same code from above - but that
> requires entering in a Password and we need this done automattically.
> Also - the 2nd command does not work using Run as but the First command
> does - i find that strange as well.
>
> ------------
> cd c:\windows\system32
> runas /profile /user:Domain\Account "cscript prnport.vbs -a -r
> IP_192.168.1.115 -h 192.168.1.115 -o raw -n 9100"
> runas /profile /user:Domain\Account "cscript prnmngr.vbs -a -p "Xerox
> Printer" -m "Xerox 4510" -r "IP_192.168.1.115""
> pause
> -------------
>
>
> If you can assist with another way of doing this or a way of doing this
> using the same code would be really helpful.
> I've done alot of research online and there seems to be no real way of
> doing this.
> I have tried many 3rd party applications that is suppposed to make this
> work easily but I have not had any luck with getting it to work.
>
> Let me know.
>
> Thanks,
> Steve
>
>
>
>




Reply With Quote
  #3  
Old 29-04-2008
Member
 
Join Date: Apr 2008
Posts: 1
Hello

I have a similar need. The script is working fine but i need to specify where the driver is for the printer that i am wanting to install

how can i do this

many thanks

Gareth

Reply With Quote
  #4  
Old 08-11-2008
Member
 
Join Date: Nov 2008
Posts: 1
Re: batch file to install printer HERE'S A TEMPLATE...

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

Reply With Quote
Reply

  TechArena Community > Technical Support > Computer Help > Windows XP > XP Print Fax


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Similar Threads for: "batch file to install printer"
Thread Thread Starter Forum Replies Last Post
Dos batch file to sort files based on file names. Jon Osborn Server Scripting 9 17-06-2009 11:06 AM
Is there a batch file to install software bigboy Windows Software 3 06-05-2009 11:20 PM
Batch file to copy a file from the local drive to a computer on lan? dudelearn Tips & Tweaks 3 12-03-2009 12:56 PM
How to install Atl service program using batch file on vista rajendersaini@gmail.com Vista Security 1 23-07-2007 06:50 PM


All times are GMT +5.5. The time now is 06:36 AM.