![BATCH スクリプトを使用して Windows で IP 経由でプリンターを追加する方法](https://rvso.com/image/1284413/BATCH%20%E3%82%B9%E3%82%AF%E3%83%AA%E3%83%97%E3%83%88%E3%82%92%E4%BD%BF%E7%94%A8%E3%81%97%E3%81%A6%20Windows%20%E3%81%A7%20IP%20%E7%B5%8C%E7%94%B1%E3%81%A7%E3%83%97%E3%83%AA%E3%83%B3%E3%82%BF%E3%83%BC%E3%82%92%E8%BF%BD%E5%8A%A0%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95.png)
TCP/IP ポートを使用してローカルにプリンターを追加する BATCH スクリプトを作成できるようにしたいと考えています。必要な引数は、プリンター名、ドライバーの場所 (.inf)、IP アドレス、およびコンピューター名であると想定しています。
誰か助けてくれる人はいますか?
答え1
これはprintuiを数回呼び出すことで実現できます。詳細についてはこのページをご覧ください電話をかけたいようです
rundll32 printui.dll,PrintUIEntry /ga
ただし、ネットワーク経由で INF ファイルを使用してプリンターを指定する方法がわかりません。
数年前、ネットワーク経由でプリンターをインストールするスクリプトを書きました。このスクリプトは、Samba で共有されるプリンターで使用することを想定しているため、ドライバーを指定する必要はありません。この方法で共有されていないプリンターを追加しようとしている場合、これが機能するかどうかはわかりません。ただし、これを開始点として使用して、実行方法を理解することができます。
@echo off
::
::This script adds a single printer to the default user profile.
::NOTE: Printer names with spaces will NOT be accepted.
::Usage: run addprinters and follow onscreen directions
cls
echo This script adds the specified local or network printer
echo to the deafult account for all existing/new users.
echo *IMPORTATNT* Printer names with spaces will NOT be accepted.
echo *******************************************************
SET /P target=Enter target computer name (this compupter)
SET /P printer=Enter Printserver/Printername (do not include \\)
echo Attempting to add %printer% for all users on %target%
rundll32 printui.dll,PrintUIEntry /ga /c\\%target% /n\\%printer%
echo New printers will NOT appear until spooler is restarted.
SET /P reset=Reset print spooler Y/N?
if "%reset%"=="y" goto spooly
goto end
:spooly
start /wait sc \\%target% stop spooler
start /wait sc \\%target% start spooler
echo Print Spooler Service restarted.
:end
試してみたい場合は、このテキストを .cmd ファイルに保存して実行してください。