可不可以用批处理设置共享打印机?怎样写?
比如,我在LPT1上接了一台叫CANONLBP的打印机。现在需要用一个批处理实现把这台计算机共享或不共享。不知道改怎么写。说明一下,我问的不是怎么去连接别人的共享打印机。...
比如,我在LPT1上接了一台叫CANONLBP的打印机。现在需要用一个批处理实现把这台计算机共享或不共享。不知道改怎么写。
说明一下,我问的不是怎么去连接别人的共享打印机。哪位高人请帮我写一下命令。非常感谢。 展开
说明一下,我问的不是怎么去连接别人的共享打印机。哪位高人请帮我写一下命令。非常感谢。 展开
2个回答
展开全部
供参考,需要几个文件来配置
CODE: [Copy to clipboard]
--------------------------------------------------------------------------------
echo off
cls
rem 以下是判断端口
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 以下是添加端口在注册表中的信息
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 以下是重新启动打印服务,使新端口生效
:restartservice
cls
echo.
echo 请稍候,正在启用打印机端口!
echo.
net stop spooler >nul 2>nul
net start spooler >nul 2>nul
rem 以下是添加打印机
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 请稍等,正在添加打印机%count%,相关信息如下:
echo.
echo IP :%pIP%
echo 名称 :%pname%
echo 型号 :%pmodel%
echo 驱动 :%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 打印机添加完毕!
pause
exit
★★★★★★★★★
网络打印服务器配置文件“打印机1.txt”的内容:
--------------------------------------------------------------------------------
打印机IP=44.44.44.44
打印机名称=柯尼卡 220 打印服务器
打印机型号=KONICA MINOLTA 220
打印机INF位置=D:\sysbak\打印机\220驱动\TSK.inf
★★★★★★★★★
本地打印机配置文件“打印机2.txt”的内容:
--------------------------------------------------------------------------------
打印机IP=LPT1:
打印机名称=本地HP 3050
打印机型号=HP LaserJet 3050 Series PCL 5e
打印机INF位置=D:\sysbak\打印机\hp3055\Drivers\2K_XP_Vista\hppcp501.inf
=====================================================
另外,CSDN上一个批处理,不知道能不能用:
reg delete HKEY_CURRENT_USER\Printers\Connections\ /f
start \\fax2\新纸打印机
start \\fax\二手打印机
start \\fax2\新纸打印机中间
CODE: [Copy to clipboard]
--------------------------------------------------------------------------------
echo off
cls
rem 以下是判断端口
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 以下是添加端口在注册表中的信息
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 以下是重新启动打印服务,使新端口生效
:restartservice
cls
echo.
echo 请稍候,正在启用打印机端口!
echo.
net stop spooler >nul 2>nul
net start spooler >nul 2>nul
rem 以下是添加打印机
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 请稍等,正在添加打印机%count%,相关信息如下:
echo.
echo IP :%pIP%
echo 名称 :%pname%
echo 型号 :%pmodel%
echo 驱动 :%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 打印机添加完毕!
pause
exit
★★★★★★★★★
网络打印服务器配置文件“打印机1.txt”的内容:
--------------------------------------------------------------------------------
打印机IP=44.44.44.44
打印机名称=柯尼卡 220 打印服务器
打印机型号=KONICA MINOLTA 220
打印机INF位置=D:\sysbak\打印机\220驱动\TSK.inf
★★★★★★★★★
本地打印机配置文件“打印机2.txt”的内容:
--------------------------------------------------------------------------------
打印机IP=LPT1:
打印机名称=本地HP 3050
打印机型号=HP LaserJet 3050 Series PCL 5e
打印机INF位置=D:\sysbak\打印机\hp3055\Drivers\2K_XP_Vista\hppcp501.inf
=====================================================
另外,CSDN上一个批处理,不知道能不能用:
reg delete HKEY_CURRENT_USER\Printers\Connections\ /f
start \\fax2\新纸打印机
start \\fax\二手打印机
start \\fax2\新纸打印机中间
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询