2012-08-07

使用batch指令來新增網路印表機[TCP/IP模式]

【TCP/IP方式的網路印表機】
參考網址:http://www.linuxreaders.com/2010/10/installing-printer-from-command-line-windows.html

@echo off
rem "Printer Automation"
rem "Created by Vidyadhar"
rem "Mapping the network drive"
cd \
net use v: /DELETE
net use v: \\192.168.1.2\printer\

rem "Creating TCP/IP port"
cd \
cscript %windir%\system32\prnport.vbs -d -r IP_192.168.1.10
cscript %windir%\system32\prnport.vbs -a -r IP_192.168.1.10 -o raw -n 9100 -h 192.168.1.10

rem "Installing Printer's Driver"
cscript %windir%\system32\prndrvr.vbs -a -m "HP LaserJet P2015 Series PCL 6" -h "V:\\2015\\" -i "V:\\2015\\hppcp604.inf"

rem "Installing Printer"
cscript %windir%\system32\prnmngr.vbs -a -p "HP_Printer" -m "HP LaserJet P2015 Series PCL 6" -r "IP_192.168.1.10"

rem "Making it Default printer"
cscript %windir%\system32\prnmngr.vbs -p "HP_Printer" -t

rem "Deleting mapped drive"
net use v: /DELETE

使用batch指令來新增網路印表機[網芳模式]


【網芳分享方式的網路印表機】
參考網址:http://tw.myblog.yahoo.com/jw!YhJldjaGBwQWzZNZFrJo/article?mid=14&prev=-1&next=13

rundll32.exe shell32.dll,SHHelpShortcuts_RunDLL AddPrinter
rundll32 printui.dll,PrintUIEntry /y /q /u /in /n\\server_name\printer_name
rundll32 printui.dll,PrintUIEntry /if /b "PDF Printer" /f c:\oracle\ge684\ntprint.inf /r "FILE:" /m "PDF Printer"
命令提示列下,使用如下指令可用批次檔設定網路印表機,做到預先大量設定。
語法:
新增網路印表機
rundll32 printui.dll,PrintUIEntry /in /q /n \\server\share printer name
刪除網路印表機
rundll32 printui.dll,PrintUIEntry /dn /n \\server\share printer name
設定為預設印表機
rundll32 printui.dll,PrintUIEntry /y /q /n \\server\share printer name
使用方式: rundll32 printui.dll,PrintUIEntry [options] [@commandfile]
  /a[file] 二進位檔案名稱
  /b[name] 基本印表機名稱
  /c[name] 如果動作發生在遠端電腦,則是電腦的 UNC 名稱
  /dl 刪除本機印表機
  /dn 刪除網路印表機連線
  /dd 刪除印表機驅動程式
  /e 顯示列印喜好設定
  /f[file]  可以是 inf 檔案或輸出檔案
  /ga 增加每台電腦的印表機連線
  /ge 列舉每台電腦的印表機連線
  /gd 刪除每台電腦的印表機連線
  /h[arch] 以下驅動程式結構之一 Alpha | Intel | Mips | PowerPC
  /ia 使用 inf 檔來安裝印表機驅動程式
  /id 用新增印表機驅動程式精靈來新增印表機驅動程式
  /if 使用 inf 檔來安裝印表機
  /ii 啟動新增印表機精靈及 inf 檔來安裝印表機
  /il 使用新增印表機精靈來安裝印表機
  /in 新增網路印表機連線
  /j[provider]  列印提供者名稱
  /k 列印測試頁到指定的印表機。安裝印表機時,不可和指令相結合。
  /l[path]  印表機驅動程式來源路徑
  /m[model]  印表機驅動程式機型名稱
  /n[name]  電腦名稱
  /o 顯示印表機佇列檢視
  /p 顯示印表機內容
  /q 安靜模式,不顯示錯誤訊息
  /r[連接埠] 連接埠名稱
  /s 顯示伺服器內容
  /Ss 將印表機設定值儲存到檔案
  /Sr 將印表機設定值從檔案還原
  儲存或還原必須放在指令結尾的印表機設定值選項旗標:
 2 PRINTER_INFO_2
 7 PRINTER_INFO_7
 c 色彩設定檔
 d 印表機資料
 s 安全性描述元
 g 通用 DevMode
 m 最小設定值
 u 使用者 DevMode
 r 解決名稱衝突
 f 強制名稱
 p 解決連接埠
  /u 如果已經安裝了,使用現存的印表機驅動程式
  /t[#] 基本索引頁從零開始
  /v[verison] 指定以下驅動程式版本之一,Windows 95 或 98 | Windows NT 3.1 | Windows NT 3.5 或 3.51 | Windows NT 3.51 | Windows NT 4.0 | Windows NT 4.0 或 2000 | Windows 2000
  /w 如果在 inf 檔內找不到指定的驅動程式,提示一個驅動程式給使用者
  /y 設定為預設印表機
  /Xg 取得印表機設定值
  /Xs 指定印表機設定值
  /z 不自動共用這個印表機
  /Z 共用這個印表機,只能和 /if 選項配合使用
  /? 說明訊息
  @[file] 指令行引數檔案
範例:
  執行伺服器內容: 
rundll32 printui .dll ,PrintUIEntry /s /t1 /n\\machine
  執行印表機內容: 
rundll32 printui .dll ,PrintUIEntry /p /n\\machine\printer
  在本機執行新增印表機精靈: 
rundll32 printui .dll ,PrintUIEntry /il
  執行新增印表機精靈於 \\machine:
rundll32 printui.dll,PrintUIEntry /il /c\\machine
  執行佇列檢視: 
rundll32 printui .dll ,PrintUIEntry /o /n\\machine\printer
  執行 inf 檔安裝:
rundll32 printui.dll,PrintUIEntry /if /b "Test Printer" /f %windir%\inf\ntprint.inf /r "lpt1:" /m "AGFA-AccuSet v52.3"
  使用 inf 檔執行新增印表機精靈:
rundll32 printui.dll,PrintUIEntry /ii /f %windir%\inf\ntprint.inf
  新增每台電腦印表機連線:
rundll32 printui.dll,PrintUIEntry /ga /c\\machine /n\\machine\printer /j"LanMan Print Services"
  刪除每台電腦的印表機連線:
rundll32 printui.dll,PrintUIEntry /gd /c\\machine /n\\machine\printer
  列舉每台電腦的印表機連線:
rundll32 printui.dll,PrintUIEntry /ge /c\\machine
  使用 inf 檔新增印表機驅動程式:
rundll32 printui.dll,PrintUIEntry /ia /c\\machine /m "AGFA-AccuSet v52.3" /h "Intel" /v "Windows 2000" /f %windir%\inf\ntprint.inf
  移除印表機驅動程式:
rundll32 printui.dll,PrintUIEntry /dd /c\\machine /m "AGFA-AccuSet v52.3" /h "Intel" /v "Windows 2000"
  設定為預設印表機:
rundll32 printui.dll,PrintUIEntry /y /n "printer"
  設定印表機註解:
rundll32 printui.dll,PrintUIEntry /Xs /n "printer" comment "My Cool Printer"
  取得印表機設定值:
rundll32 printui.dll,PrintUIEntry /Xg /n "printer"
  取得印表機設定值並將結果儲存在檔案:
rundll32 printui.dll,PrintUIEntry /f "results.txt" /Xg /n "printer"
  設定印表機設定值指令使用方式
rundll32 printui.dll,PrintUIEntry /Xs /n "printer" ?
  將所有印表機設定值存放到檔案:
rundll32 printui.dll,PrintUIEntry /Ss /n "printer" /a "file.dat"
  從檔案還原所有的印表機設定值:
rundll32 printui.dll,PrintUI /Sr /n "printer" /a "file.dat"
  將印表機資訊存放到等級 2 的檔案中:
rundll32 printui.dll,PrintUIEntry /Ss /n "printer" /a "file.dat" 2
  還原檔案印表機安全性描述元:
rundll32 printui.dll,PrintUIEntry /Sr /n "printer" /a "file.dat" s
  還原檔案印表機通用 devmode 及印表機資料:
rundll32 printui.dll,PrintUIEntry /Sr /n "printer" /a "file.dat" g d
  還原檔案最小設定值及解析連接埠名稱:
rundll32 printui.dll,PrintUIEntry /Sr /n "printer" /a "file.dat" m p

start /wait rundll32 printui.dll,PrintUIEntry /if /b "Epson LQ-1000" /f %windir%\inf\ntprint.inf /r "lpt1:" /m "Epson LQ-1000"
start /wait rundll32 printui.dll,PrintUIEntry /y /n "Epson LQ-1000"
exit
rundll32 printui.dll,PrintUIEntry /Xs /n printer <key> [-|+]<value> <key> [-|+]<value> etc.
機碼: PrinterName 數值: <string>
機碼: ShareName 數值: <string>
機碼: PortName 數值: <string>
機碼: DriverName 數值: <string>
機碼: Comment 數值: <string>
機碼: Location 數值: <string>
機碼: SepFile 數值: <string>
機碼: PrintProcessor 數值: <string>
機碼: Datatype 數值: <string>
機碼: Parameters 數值: <string>
機 碼: Attributes 數值: <Queued|Direct|Default|Shared|Hidden|Network|Local|EnableDevq|KeepPrintedJobs|DoCompleteFirst|WorkOffline|EnableBidi|RawOnly|Published>
機碼: Priority 數值: <integer>
機碼: DefaultPriority 數值: <integer>
機碼: StartTime 數值: <integer>
機碼: UntilTime 數值: <integer>
機碼: Status 數值: <Pause|Resume|Purge>
機碼: ClientSideRender 數值:
範例:
   暫停印表機:
rundll32 printui.dll,PrintUIEntry /Xs /n "printer" status pause
   設定印表機列印方向:
rundll32 printui.dll,PrintUIEntry /Xs /n "printer" attributes +direct
   設定印表機多工處理:
rundll32 printui.dll,PrintUIEntry /Xs /n "printer" attributes -direct
   設定印表機,保留無法對應的文件,並在列印後保留列印文件: 
rundll32 printui.dll,PrintUIEntry /Xs /n "printer" attributes +EnableDevq attributes +KeepPrintedJobs
   共用印表機: 
rundll32 printui.dll,PrintUIEntry /Xs /n "printer" sharename "Share" attributes +Shared
   停止共用印表機: 
rundll32 printui.dll,PrintUIEntry /Xs /n "printer" attributes -Shared
   將佇列優先順序設定成 50: 
rundll32 printui.dll,PrintUIEntry /Xs /n "printer" priority 50
   將印表機重新命名成 Printer1: 
rundll32 printui.dll,PrintUIEntry /Xs /n "printer" printername "Printer1"