文章編號: 321025 - 上次校閱: 2007年3月1日 - 版次: 5.5

如何: 以程式設計方式印表機和印表機連接埠使用建立 PrinterAdmin (prnadmin.dll) 與 Microsoft Windows 2000 中的 Visual Basic 指令碼

系統提示本文適用於您使用的作業系統之外的作業系統。與您不相關的文章內容已停用。
注意事項
這份文件適用於 Windows 2000。Windows 2000 支援的結束 2010 7 月 13,Windows 2000 End-of-Support Solution Center (http://support.microsoft.com/?scid=http%3a%2f%2fsupport.microsoft.com%2fwin2000) 是規劃您的遷移策略,從 Windows 2000 的起點。如需詳細資訊請參閱 Microsoft Support Lifecycle Policy (http://support.microsoft.com/lifecycle/) ]。

在此頁中

全部展開 | 全部摺疊

結論

本文將逐步告訴您,如何以程式設計方式建立藉由使用 Microsoft Windows 2000 中的 [PrinterAdmin 工具 (Prnadmin.dll) 和 Visual Basic 指令碼的 [印表機和印表機連接埠。

prnadmin.dll 的概觀

PrinterAdmin 均可使用 Microsoft Windows 2000 資源工具箱 」。這是一個元件物件模型 COM 為基礎的工具讓系統管理員可以用來管理印表機、 驅動程式及本機和遠端 Windows 2000 電腦上的連接埠。PrinterAdmin 提供透過指令碼的使用印表機的大型、 非互動式控制項。您可以建立您自己的指令碼或修改其中一個範例指令碼所提供的 PrinterAdmin 執行下列工作:
  • 新增及刪除印表機。
  • 新增及刪除印表機驅動程式。
  • 新增及刪除印表機連接埠。
  • 新增及刪除表單。
  • 檢視特定電腦上的印表機、 連接埠、 驅動程式和表單的清單。
  • 控制並設定印表機。
  • 列印測試頁。
  • 複製列印伺服器。
這份文件中的 Visual Basic 指令碼範例示範如何使用 Prnadmin.dll 從遠端加入 Windows 2000 電腦上的 [印表機和印表機連接埠。指令碼會執行下列工作:
  • 在用戶端電腦上建立新的連接埠。本範例在連接埠會指向電腦的硬碟上的 [C:\MyFolder\MyPort] 資料夾。
  • 安裝用戶端電腦使用新的連接埠的印表機。
  • (在其中儲存已傳送到新的印表機的文件) 的用戶端電腦的硬碟上建立 C:\MyFolder 資料夾。

如何使用 Visual Basic 指令碼 prnadmin.dll 新增印表機和印表機連接埠

  1. 啟動 [記事本],然後開啟新的文字檔。
  2. 複製並貼入文字檔案中的下列行:

    注意: 若要使用 Prnadmin.dll,它必須登錄在用戶端電腦。指令碼會註冊 Prnadmin.dll 從伺服器上的位置。 請確定將 \\Servername\Foldername 變更 Prnadmin.dll 檔案在您的伺服器上正確的路徑
    
    '******** Register prnadmin.dll file on client computer *******
    
    Set WshShell = Wscript.CreateObject("Wscript.Shell")
    
    WshShell.Run "regsvr32 /s \\ServerName\FolderName\Prnadmin.dll",1,TRUE
    
    '************** Create the port first *******************************
    
    dim oPort
    
    dim oMaster
    
    set oPort = CreateObject("Port.Port.1")
    
    set oMaster = CreateObject("PrintMaster.PrintMaster.1")
    
    oPort.PortName = "C:\MyFolder\MyPort"
    
    oPort.PortType = 3
    
    oMaster.PortAdd oPort
    
    if Err <> 0 then
    
    msgbox "There was an error creating the port."
    
    end if
    
    '********************************************************************
    
    '************** Create the printer second ***************************
    'Change MyPrinter to the name of the printer that you are adding.
    'Change PrinterDriver to the name of the printer driver that you are adding.
    
    
    dim oPrinter
    
    set oPrinter = CreateObject("Printer.Printer.1")
    
    oPrinter.PrinterName = "MyPrinter"		' name of the printer as it appears in the Printers folder
    
    oPrinter.DriverName = "PrinterDriver"		' name that is referenced in ntprint.inf
    
    oPrinter.PortName = "C:\MyFolder\MyPort"		' Specify a port name. Can also point to LPT or COM port.
    
    oMaster.PrinterAdd oPrinter
    If Err <> 0 then
    
    msgbox "There was an error creating the printer."
    
    end if
    
    '********************************************************************
    
    '************** Create the directory third ***************************
    
    Dim filesys
    
    Set filesys = wscript.createobject("Scripting.FilesystemObject")
    
    filesys.CreateFolder "C:\MyFolder\"			' Create a folder as a repository for the faxes.
    
    If Err <> 0 then
    
    msgbox "There was an error creating the MyFolder folder."
    
    end if
    
    '********************************************************************
    
    msgbox "The script is finished."
    
    					
  3. 自訂 (視) 的指令碼,以符合您的需求。
  4. 在 [檔案] 功能表上按一下 [另存]。檔案名稱] 方塊中 (例如,MyPrinter.vbs),使用.vbs 檔案名稱延伸模組中指令碼的名稱指定您要儲存該檔案,然後按一下 [儲存 的位置的型別。

    注意: 請確定您包含在雙引號 ("") 時鍵入檔案名稱。這個動作會建立具有.vbs 副檔名之檔案。
  5. 結束 [記事本]。
  6. 將指令碼部署到使用者的電腦。

    執行指令碼時建立新的連接埠],、 安裝印表機,並在印表機出現在用戶端電腦的 [印表機] 資料夾。


?考

如需有關 PrinterAdmin 工具的詳細資訊,請參閱 Prnadmin.doc 檔在 Windows 2000 資源工具箱 」 中可用的。(如果 Windows 2000 資源工具箱 」 安裝到預設位置) 時,Prnadmin.doc 檔案位於程式 Files\Resource 套件資料夾中。

如需有關 Windows 2000 資源工具箱 」 的詳細資訊,請造訪下列 Microsoft 網站]:
http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/default.mspx (http://www.microsoft.com/technet/prodtechnol/windows2000serv/reskit/default.mspx)
如需有關如何使用 Visual Basic 指令碼加入預設印表機的詳細資訊,按一下下面的文件編號,檢視 「 Microsoft 知識庫 」 中的發行項:
263226? (http://support.microsoft.com/kb/263226/EN-US/ ) 如何新增預設的印表機使用 Visual Basic 指令碼
如需有關如何移轉列印伺服器的設定,Windows NT 4.0 和 Windows 2000 電腦之間的詳細資訊,按一下下面的文件編號,檢視 「 Microsoft 知識庫 」 中的發行項:
315983? (http://support.microsoft.com/kb/315983/EN-US/ ) 如何: 移轉印表機 Migrator 2000 工具使用的 Windows NT 4.0 或 Windows 2000 電腦間的印表機伺服器組態

這篇文章中的資訊適用於:
  • Microsoft Windows 2000 Server
  • Microsoft Windows 2000 Advanced Server
  • Microsoft Windows 2000 Professional Edition
關鍵字:?
kbmt kbhowto kbhowtomaster KB321025 KbMtzh
機器翻譯機器翻譯
重要:本文是以 Microsoft 機器翻譯軟體翻譯而成,而非使用人工翻譯而成。Microsoft 同時提供使用者人工翻譯及機器翻譯兩個版本的文章,讓使用者可以依其使用語言使用知識庫中的所有文章。但是,機器翻譯的文章可能不盡完美。這些文章中也可能出現拼字、語意或文法上的錯誤,就像外國人在使用本國語言時可能發生的錯誤。Microsoft 不為內容的翻譯錯誤或客戶對該內容的使用所產生的任何錯誤或損害負責。Microsoft也同時將不斷地就機器翻譯軟體進行更新。
按一下這裡查看此文章的英文版本:321025? (http://support.microsoft.com/kb/321025/en-us/ )
Microsoft及(或)其供應商不就任何在本伺服器上發表的文字資料及其相關圖表資訊的恰當性作任何承諾。所有文字資料及其相關圖表均以「現狀」供應,不負任何擔保責任。Microsoft及(或)其供應商謹此聲明,不負任何對與此資訊有關之擔保責任,包括關於適售性、適用於某一特定用途、權利或不侵權的明示或默示擔保責任。Microsoft及(或)其供應商無論如何不對因或與使用本伺服器上資訊或與資訊的實行有關而引起的契約、過失或其他侵權行為之訴訟中的特別的、間接的、衍生性的損害或任何因使用而喪失所導致的之損害、資料或利潤負任何責任。