add a network printer, with BAT file.

  • Thread starter Thread starter Guillermo Guerrero
  • Start date Start date
G

Guillermo Guerrero

Hi there !!!

Any one knows if there is a way to create a BAT file, to
add a network printer???


Thanks
 
@ECHO OFF
VER | FIND "Windows 2000" >NUL
IF ERRORLEVEL 1 GOTO Syntax

SETLOCAL
SET Printer=%1
SET RemotePC=%2

:: Check printer specified
IF NOT DEFINED Printer GOTO Syntax
IF NOT "%Printer:~0,2%"=="\\" GOTO Syntax
FOR /F "tokens=1* delims=\" %%A IN ('ECHO.%Printer%') DO (
SET PrintServer=%%A
Set PrintShare=%%B
)
IF NOT DEFINED PrintShare GOTO Syntax
PING %PrintServer% -n 1 -w 1000 2>&1 | FIND "TTL=" >NUL
IF ERRORLEVEL 1 GOTO Syntax
NET VIEW \\%PrintServer% 2>&1 | FIND /I "%PrintShare%" >NUL
IF ERRORLEVEL 1 GOTO Syntax

:: Check remote PC if specified
IF DEFINED RemotePC SET RemotePC=%RemotePC:\=%
IF DEFINED RemotePC(
PING %RemotePC% -n 1 -w 1000 2>&1 | FIND "TTL="
IF ERRORLEVEL 1 GOTO Syntax
SET RemotePC=/C\\%RemotePC%
)

:: Install the printer on the specified computer
RUNDLL32.EXE PRINTUI.DLL, PrintUIEntry /ga /n%Printer% %
RemotePC%
IF NOT ERRORLEVEL 1 ECHO Printer installed, please reboot %
RemotePC%

ENDLOCAL
GOTO:EOF

:Syntax
ECHO.
ECHO AddPrint.bat, Version 1.00 for Windows 2000
ECHO Install a network printer on any PC on the network
ECHO.
ECHO Usage: ADDPRINT \\print_server\printer_share [
remote_pc ]
ECHO.
ECHO Where: "print_server" is the print
server name or IP address
ECHO "printer_share" is the share
name for the printer
ECHO "remote_pc" is the PC that
will be using the
ECHO network printer -
- default is local PC
ECHO.
ECHO Written by Rob van der Woude
ECHO http://www.robvanderwoude.com

IF "%OS%"=="Windows_NT" ENDLOCAL
 
In addition to the other reply, con2prt.exe from the resource kit
(downloadable from MS) can do this.
 
that only works from the run line or command prompt. when
written in a batch file, the OS doesn't know what to do
with it. try it!
 
That's odd, because I use batch files to map printers every day in Windows
2000 and it always works for me.
 
Redirecting to LPT ports? That works if they have local admin rights, but
even then isn't the best solution.
 
I will grant that is true. Far better to add the printer through the GUI so
you can get the best functionality from it. But nonetheless it can be done.

--
Richard G. Harper [MVP Win9x] (e-mail address removed)
* PLEASE post all messages and replies in the newsgroups
* for the benefit of all. Private mail is usually not replied to.
* HELP us help YOU ... http://www.dts-l.org/goodpost.htm


"Lanwench [MVP - Exchange]"
 
Yep. Have you ever looked at con2prt.exe?
I will grant that is true. Far better to add the printer through the
GUI so you can get the best functionality from it. But nonetheless
it can be done.


"Lanwench [MVP - Exchange]"
Redirecting to LPT ports? That works if they have local admin
rights, but even then isn't the best solution.
 
Nope ... but I will. :-)

--
Richard G. Harper [MVP Win9x] (e-mail address removed)
* PLEASE post all messages and replies in the newsgroups
* for the benefit of all. Private mail is usually not replied to.
* HELP us help YOU ... http://www.dts-l.org/goodpost.htm


"Lanwench [MVP - Exchange]"
Yep. Have you ever looked at con2prt.exe?
I will grant that is true. Far better to add the printer through the
GUI so you can get the best functionality from it. But nonetheless
it can be done.


"Lanwench [MVP - Exchange]"
Redirecting to LPT ports? That works if they have local admin
rights, but even then isn't the best solution.

Richard G. Harper wrote:
That's odd, because I use batch files to map printers every day in
Windows 2000 and it always works for me.


that only works from the run line or command prompt. when
written in a batch file, the OS doesn't know what to do
with it. try it!
 
Does anyone know whether the con2prt.exe from NT4 will work ok on 2K Server
with 2K clients? I have only been able to find con2prt available in the NT4
resource kit.

Thanks
 
I have only been able to find con2prt available in the NT4 resource kit. Does
anyone know whether this version will work on 2K server and 2K clients?

Thanks
 
I have only been able to find con2prt available in the NT4 resource kit. Does
anyone know whether this version will work on 2K server and 2K clients?

Thanks
 
I have only been able to find con2prt available in the NT4 resource kit. Does
anyone know whether this version will work on 2K server and 2K clients?

Thanks
 
Colin,

Yeah, it works just great. Loads of people use it, especially in Citrix
environments where printers become a bit hard to control.

Ryan Hanisco
MCSE, MCDBA
Flagship Integration Services
 
Back
Top