win10x64 批处理自动安装打印机

系统版本:Windows 10企业版 64位(10.0 ,版本17134)- 中文(简体)

话不多说,直接上脚本:


REM 提升管理员权限
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
    goto UACPrompt 
) else (
    goto gotAdmin 
)
:UACPrompt
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
cd /D "%~dp0"


检测文件服务器和打印机是否连接正常,和ping同理。


rem auto install
@echo off
chcp 65001 >nul
title 佳能打印机自动安装程序
color 0a
:fileserver
ping 192.168.1.23 -n 1| findstr /i "TTL" >NUL 2>NUL&& goto printer
echo 无法连接文件服务器 ...
goto end
:printer
echo =======================================
echo  !!!!! 检测文件服务器网络正常 ...!!!!!!!!!!!
echo =======================================
ping 192.168.1.6 -n 1 | findstr /i "TTL" >NUL 2>NUL&& goto driver
echo 无法连接打印机 ...
goto end

使用FTP服务器下载驱动到本地。


:driver
rem 文件服务器共享目录,存放打印机驱动文件
echo ======================================
echo  !!!!!检测打印机网络正常...!!!!!!!!!!!!!
echo ======================================
3272801
echo  开始下载驱动程序,请耐心等待,千万不要关闭本窗口......
rd /s /Q "D:\CanonDriver"
md "D:\CanonDriver"
rem 指定FTP用户名
set ftpUser=admin
rem 指定FTP密码
set ftpPass=admin
rem 指定FTP服务器地址
set ftpIP=192.168.1.23
rem 指定待下载的文件位于FTP服务器的哪个目录
set ftpFolder=CanonDriver
rem 指定从FTP下载下来的文件存放到本机哪个目录
set LocalFolder=D:\CanonDriver
set tempFolder=D:\Tempftp.txt
set ftpFile=%tempFolder%
>"%ftpFile%" (
  echo,open %ftpIP%
  echo,user %ftpUser%  
  echo %ftpPass%
  echo cd "%ftpFolder%"
  echo lcd "%LocalFolder%"
  echo prompt off
  echo bin
  echo mget *.*
  echo bye
)
start  /wait ftp -n -s:"%ftpFile%"
if errorlevel 0 goto start
echo Connect to the fileserver failed ...
goto end
:start
echo 已找到打印机驱动...
echo 删除同名打印机...
rundll32 printui.dll,PrintUIEntry /dl /n "佳能打印机" /q
echo 正在准备安装打印机,请耐心等待 ...
rem add port 
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" /v StatusUpdateInterval /t REG_DWORD /d 0x0000000a /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports" /v StatusUpdateEnabled /t REG_DWORD /d 0x00000001 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v Protocol /t REG_DWORD /d 0x00000001 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v Version /t REG_DWORD /d 0x00000001 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v HostName /t REG_SZ /d "192.168.1.6" /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v HWAddress /t REG_SZ /d "" /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v IPAddress /t REG_SZ /d "" /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v PortNumber /t REG_DWORD /d 0x0000238c /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v PortMonMibPortIndex /t REG_DWORD /d 0x00000001 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v "SNMP Community" /t REG_SZ /d "public" /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v "SNMP Enabled" /t REG_DWORD /d 0x00000000 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v "SNMP Index" /t REG_DWORD /d 0x00000000 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v Queue /t REG_SZ /d "print" /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v "Double Spool" /t REG_DWORD /d 0x00000000 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports" /v StatusUpdateInterval /t REG_DWORD /d 0x0000000a /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports" /v StatusUpdateEnabled /t REG_DWORD /d 0x00000001 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v Protocol /t REG_DWORD /d 0x00000001 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v Version /t REG_DWORD /d 0x00000001 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v HostName /t REG_SZ /d "192.168.1.6" /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v HWAddress /t REG_SZ /d "" /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v IPAddress /t REG_SZ /d "" /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v PortNumber /t REG_DWORD /d 0x0000238c /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v PortMonMibPortIndex /t REG_DWORD /d 0x00000001 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v "SNMP Community" /t REG_SZ /d "public" /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v "SNMP Enabled" /t REG_DWORD /d 0x00000000 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v "SNMP Index" /t REG_DWORD /d 0x00000000 /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v Queue /t REG_SZ /d "print" /f >nul
reg add "HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Print\Monitors\Standard TCP/IP Port\Ports\IP_192.168.1.6" /v "Double Spool" /t REG_DWORD /d 0x00000000 /f >nul
@ping 127.0.0.1 -n 2 >nul
rem restart printer service
sc stop spooler && sc start spooler 
@echo off
for /f "skip=3 tokens=4" %%i in ('sc query spooler') do set "zt=%%i" && goto :next
:next
if /i "%zt%"=="RUNNING" (
    echo.
    echo.
    echo 打印机服务运行正常,打印机安装中,此步骤需要运行几分钟,请千万别关闭本窗口 。。。
) else (
    echo 打印机服务处于停止状态。
    goto :end
)
rem 安装打印机
rundll32 printui.dll,PrintUIEntry /if /b "佳能打印机" /f "D:\CanonDriver\CNLB0CA64.INF"  /r "IP_192.168.1.6" /m "Canon iR-ADV C3520 UFR II" /z
if not errorlevel 0 goto :end
@ping 127.0.0.1 -n 6 >nul
echo.
echo 打印机已安装成功!!!
echo.
echo  将这个打印机设置为默认打印机
rundll32 printui.dll,PrintUIEntry /y /n "佳能打印机"
:end
echo.
echo.
echo 恭喜你已经全部完成设置,打印机名为"佳能打印机",请按任意键退出...
pause >nul
exit

内容来能源于网络,如有侵权请邮件 momeis@qq.com 删除。

相关推荐

发表评论

路人甲

网友评论(0)