常常都會碰到的問題,如何大量變更Client共用 Printer Server 的位置
請使用下列的Code,並儲存成VBScript 的格式
LISTING 1: Logon Script to Automatically Install New Printers
On error resume next
' This code enumerates the user's current network printer connections.
Set WshNetwork = CreateObject("WScript.Network")
Set oPrinters = WshNetwork.EnumPrinterConnections
For j = 0 to oPrinters.Count - 1 Step 2
' This code opens a comma-delimited text file containing
' the corresponding old and new printers and assigns
' each line as an array variable.
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("C:\printers.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrPrinterList = Split(strNextLine , ",")
' This section retrieves the registry value corresponding to the
' default printer and assigns the registry value as a string variable.
const HKEY_CURRENT_USER = &H80000001
strComputer = "."
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& strComputer & "\root\default:StdRegProv")
strKeyPath = "Software\Microsoft\Windows NT\CurrentVersion\Windows"
strValueName = "Device"
oReg.GetStringValue HKEY_CURRENT_USER,strKeyPath,strValueName,strValue
wscript.echo(strValue)
' This code takes both variables defined above and introduces conditional logic.
For i = 1 to Ubound(arrPrinterList)
If strValue =(arrPrinterList(0)) then
Wscript.Echo "Your default printer will be changed to: " & arrPrinterList(i)
WshNetwork.AddWindowsPrinterConnection arrPrinterList(i)
WshNetwork.SetDefaultPrinter arrPrinterList(i)
WshNetwork.RemovePrinterConnection arrPrinterList(0)
Else
If oPrinters.Item(j+1)=arrPrinterList(0) then
WshNetwork.RemovePrinterConnection arrPrinterList(0)
WshNetwork.AddWindowsPrinterConnection arrPrinterList(i)
End If
End If
wscript.sleep 15000
Next
Loop
Next
wscript.echo ""
其中上述的流程需修改的應該是c:\Printers.txt
其內容應該為
\\oldserver\oldprinter,
\\newserver\newprinter
依照上述流程,儲存後,至用戶端執行即可完成變更,亦可透過AD進行派送完成結果。
以上資訊來自於:
http://www.windowsitpro.com/article/migration/print-server-migration-40882