Purpose:
Batch - add printers according to the printer configuration file. For example, a computer needs to install a local parallel port printer and a network print server at the same time (not sharing the printer of other computers, but the printer that can be connected to the switch with a network cable).
Implementation steps:
1. Poll the "Printer X.txt" in the directory. According to the port description in it, judge whether it is a local LPT port. If it is a local LPT printer, ignore it. If it is a print server, automatically create a new TCP/IP port.
2. Restart the print service to make the newly created local IP port take effect.
3. Poll the "Printer X.txt" in the directory. According to the printer name, driver location, printer model and printer port, add the print server.
Key statement:
rundll32 printui.dll,PrintUIEntry /?
Defect:
Because I don't need local printers with USB ports and don't use shared printers, there are no statements added to judge such printers.
★★★★★★★★★
The following is the batch code
★★★★★★★★★
The content of the network print server configuration file "Printer 1.txt":
★★★★★★★★★
The content of the local printer configuration file "Printer 2.txt":
[ Last edited by exzzz on 2008-12-15 at 14:46 ]
Batch - add printers according to the printer configuration file. For example, a computer needs to install a local parallel port printer and a network print server at the same time (not sharing the printer of other computers, but the printer that can be connected to the switch with a network cable).
Implementation steps:
1. Poll the "Printer X.txt" in the directory. According to the port description in it, judge whether it is a local LPT port. If it is a local LPT printer, ignore it. If it is a print server, automatically create a new TCP/IP port.
2. Restart the print service to make the newly created local IP port take effect.
3. Poll the "Printer X.txt" in the directory. According to the printer name, driver location, printer model and printer port, add the print server.
Key statement:
rundll32 printui.dll,PrintUIEntry /?
Defect:
Because I don't need local printers with USB ports and don't use shared printers, there are no statements added to judge such printers.
★★★★★★★★★
The following is the batch code
@echo off
cls
rem The following is to judge the port
set count=0
:addreginfo
set /a count=%count%+1
if exist 打印机%count%.txt (set filename=打印机%count%.txt) else (goto eof)
for /f "tokens=2 delims==" %%a in ('type %filename% ^|findstr /I "打印机IP="') do set pIP=%%a
if /I "%pIP%"=="LPT1:" goto addreginfo
if /I "%pIP%"=="LPT2:" goto addreginfo
rem The following is to add the information in the registry about the port
set regpath1=HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_
set regpath2=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_
:addreg1
@reg add "%regpath1%%pip%" /v "Protocol" /d "00000001" /f /t REG_DWORD >nul 2>nul
@reg add "%regpath1%%pip%" /v "Version" /d "00000001" /f /t REG_DWORD >nul 2>nul
@reg add "%regpath1%%pip%" /v "HostName" /d "" /f >nul 2>nul
@reg add "%regpath1%%pip%" /v "IPAddress" /d "%pip%" /f >nul 2>nul
@reg add "%regpath1%%pip%" /v "HWAddress" /d "" /f >nul 2>nul
@reg add "%regpath1%%pip%" /v "PortNumber" /d "9100" /f /t REG_DWORD >nul 2>nul
@reg add "%regpath1%%pip%" /v "SNMP Community" /d "public" /f >nul 2>nul
@reg add "%regpath1%%pip%" /v "SNMP Enabled" /d "00000000" /f /t REG_DWORD >nul 2>nul
@reg add "%regpath1%%pip%" /v "SNMP Index" /d "00000001" /f /t REG_DWORD >nul 2>nul
:addreg2
@reg add "%regpath2%%pip%" /v "Protocol" /d "00000001" /f /t REG_DWORD >nul 2>nul
@reg add "%regpath2%%pip%" /v "Version" /d "00000001" /f /t REG_DWORD >nul 2>nul
@reg add "%regpath2%%pip%" /v "HostName" /d "" /f >nul 2>nul
@reg add "%regpath2%%pip%" /v "IPAddress" /d "%pip%" /f >nul 2>nul
@reg add "%regpath2%%pip%" /v "HWAddress" /d "" /f >nul 2>nul
@reg add "%regpath2%%pip%" /v "PortNumber" /d "9100" /f /t REG_DWORD >nul 2>nul
@reg add "%regpath2%%pip%" /v "SNMP Community" /d "public" /f >nul 2>nul
@reg add "%regpath2%%pip%" /v "SNMP Enabled" /d "00000000" /f /t REG_DWORD >nul 2>nul
@reg add "%regpath2%%pip%" /v "SNMP Index" /d "00000001" /f /t REG_DWORD >nul 2>nul
goto addreginfo
:eof
rem The following is to restart the print service to make the new port take effect
:restartservice
cls
echo.
echo Please wait, enabling the printer port!
echo.
net stop spooler >nul 2>nul
net start spooler >nul 2>nul
rem The following is to add the printer
set count=0
:instprinter
set /a count=%count%+1
if exist 打印机%count%.txt (set filename=打印机%count%.txt) else (goto over)
cls
for /f "tokens=2 delims==" %%a in ('type %filename% ^|findstr "打印机IP="') do set pIP=%%a
for /f "tokens=2 delims==" %%a in ('type %filename% ^|findstr "打印机名称="') do set pname=%%a
for /f "tokens=2 delims==" %%a in ('type %filename% ^|findstr "打印机型号="') do set pmodel=%%a
for /f "tokens=2 delims==" %%a in ('type %filename% ^|findstr "打印机INF位置="') do set pinf=%%a
echo.
echo Please wait, adding printer %count%, the relevant information is as follows:
echo.
echo IP: %pIP%
echo Name: %pname%
echo Model: %pmodel%
echo Driver: %pinf%
if /I "%pIP%"=="LPT1:" (goto ok)
if /I "%pIP%"=="LPT2:" (goto ok) else (set pip=IP_%pip%)
:ok
rundll32 printui.dll,PrintUIEntry /if /b "%pname%" /f "%pinf%" /r "%pIP%" /m "%pmodel%"
goto instprinter
:over
cls
echo.
echo Printer addition is complete!
pause
exit★★★★★★★★★
The content of the network print server configuration file "Printer 1.txt":
Printer IP=44.44.44.44
Printer Name=Konica 220 Print Server
Printer Model=KONICA MINOLTA 220
Printer INF Location=D:\sysbak\Printers\220 Drivers\TSK.inf★★★★★★★★★
The content of the local printer configuration file "Printer 2.txt":
Printer IP=LPT1:
Printer Name=Local HP 3050
Printer Model=HP LaserJet 3050 Series PCL 5e
Printer INF Location=D:\sysbak\Printers\hp3055\Drivers\2K_XP_Vista\hppcp501.inf[ Last edited by exzzz on 2008-12-15 at 14:46 ]
Attachments


