欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

win10x64 批处理自动安装打印机

程序员文章站 2022-06-03 10:24:04
系统版本:Windows 10企业版 64位(10.0 ,版本17134)- 中文(简体) 话不多说,直接上脚本: ......

系统版本: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"

rem auto install
@echo off
chcp 65001 >nul
title 柯美c226打印机自动安装程序
color 0a :printer ping 192.168.1.100 -n 1 | findstr /i "ttl" >nul 2>nul && goto fileserver echo cannot connect to the printer ... goto end :fileserver echo detected the printer is online ... ping 192.168.1.200 -n 1 | findstr /i "ttl" >nul 2>nul && goto driver echo cannot find any drivers of the printer ... goto end :driver

rem 文件服务器共享目录,存放打印机驱动文件
net use \\192.168.1.200\fileserver /delete >nul net use \\192.168.1.200\fileserver password /user:username >nul if errorlevel 0 goto start echo connect to the fileserver failed ... goto end :start echo driver found ... rundll32 printui.dll,printuientry /dl /n "konica minolta c266seriesps" /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.100" /v protocol /t reg_dword /d 0x00000002 /f >nul reg add "hkey_local_machine\system\currentcontrolset\control\print\monitors\standard tcp/ip port\ports\ip_192.168.1.100" /v version /t reg_dword /d 0x00000002 /f >nul reg add "hkey_local_machine\system\currentcontrolset\control\print\monitors\standard tcp/ip port\ports\ip_192.168.1.100" /v hostname /t reg_sz /d "192.168.1.100" /f >nul reg add "hkey_local_machine\system\currentcontrolset\control\print\monitors\standard tcp/ip port\ports\ip_192.168.1.100" /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.100" /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.100" /v portnumber /t reg_dword /d 0x00000203 /f >nul reg add "hkey_local_machine\system\currentcontrolset\control\print\monitors\standard tcp/ip port\ports\ip_192.168.1.100" /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.100" /v "snmp enabled" /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.100" /v "snmp index" /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.100" /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.100" /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.100" /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.100" /v protocol /t reg_dword /d 0x00000002 /f >nul reg add "hkey_local_machine\system\controlset001\control\print\monitors\standard tcp/ip port\ports\ip_192.168.1.100" /v version /t reg_dword /d 0x00000002 /f >nul reg add "hkey_local_machine\system\controlset001\control\print\monitors\standard tcp/ip port\ports\ip_192.168.1.100" /v hostname /t reg_sz /d "192.168.1.100" /f >nul reg add "hkey_local_machine\system\controlset001\control\print\monitors\standard tcp/ip port\ports\ip_192.168.1.100" /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.100" /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.100" /v portnumber /t reg_dword /d 0x00000203 /f >nul reg add "hkey_local_machine\system\controlset001\control\print\monitors\standard tcp/ip port\ports\ip_192.168.1.100" /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.100" /v "snmp enabled" /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.100" /v "snmp index" /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.100" /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.100" /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.100" /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 "konica minolta c266seriesps" /f "\\fileserver\software\打印机驱动\柯美226_windows\win_x64\koaxla__.inf" /r "ip_192.168.1.100" /m "konica minolta c266seriesps" /z if not errorlevel 0 goto :end @ping 127.0.0.1 -n 6 >nul echo. echo 打印机已安装成功!!! echo. rem public setting reg add "hkey_current_user\software\konica minolta\konica minolta c266seriesps\konica minolta c266seriesps\authentication" /v authtype /t reg_dword /d 0x00000003 /f >nul reg add "hkey_current_user\software\konica minolta\konica minolta c266seriesps\konica minolta c266seriesps\authentication" /v usertype /t reg_dword /d 0x00000000 /f >nul reg add "hkey_current_user\software\konica minolta\konica minolta c266seriesps\konica minolta c266seriesps\authentication" /v username /t reg_sz /d "" /f >nul reg add "hkey_current_user\software\konica minolta\konica minolta c266seriesps\konica minolta c266seriesps\authentication" /v userpass /t reg_binary /d "" /f >nul rem 将这个打印机设置为默认打印机 rundll32 printui.dll,printuientry /y /n "konica minolta c266seriesps" :end echo. echo. echo press any key to quit. pause >nul exit