在VBScript中添加排除项

时间:2019-01-29 01:42:26

标签: server pint

我们将员工打印机服务器切换到Windows 2016,并且已经有700-800名员工被映射到旧服务器上的打印机队列。我们正在寻找一个脚本来替换服务器名称/重新映射人员到相同的打印机队列,但是在新服务器上并保持默认打印机不变。此VBScript将放入域登录脚本中,并将在工作人员登录时重新映射打印机。我发现此VBScripting在我们的系统中运行良好。除了我需要排除一个需要在映射过程中进行安装的打印机队列之外。因此,我想排除该打印机,以便脚本忽略通过重新传递到新服务器上的该打印机并继续操作。这样,我们可以将这8名员工打印机手动重新映射到服务器。我不能为该脚本添加if,因为我不知道VBscripting。这是脚本,该特殊打印机的名称是“ RD Communication”:

On Error Resume Next 
Function GetDefaultPrinter() 
sRegVal = "HKCU\Software\Microsoft\Windows       
NT\CurrentVersion\Windows\Device" 
sDefault = "" 
On Error Resume Next 
sDefault = objShell.RegRead(sRegVal) 
sDefault = Left(sDefault ,InStr(sDefault, ",") - 1) 
On Error Goto 0 
GetDefaultPrinter = sDefault 
End Function 
Set objNetwork = CreateObject ("Wscript.Network") 
Set objShell = CreateObject ("WScript.Shell") 
Set objFSO = CreateObject ("Scripting.FileSystemObject") 
LogonServer = objShell.ExpandEnvironmentStrings("%logonserver%") 
UserName = objShell.ExpandEnvironmentStrings("%username%") 
strComputer = "." 
PrintServer = "HCLStaffPrinter1" 
PrintServer = LCase (PrintServer) 
Err.Clear 
Set objWMIService = GetObject("winmgmts:" & _ 
"{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2") 
If Err.Number Then 
wscript.echo ("Error : " & Err.Number & ": " & Err.Description & VbCrLf) 
Err.Clear 
Else 
ImpDefault = GetDefaultPrinter 
Set colInstalledPrinters = objWMIService.ExecQuery _ 
("SELECT * FROM Win32_Printer") 
For Each objPrinter in colInstalledPrinters 
PrinterArray = Split (objPrinter.Name , "\") 
If (LCase(objPrinter.ServerName) <> "") and 
(LCase (objPrinter.ServerName) <> "\\" & PrintServer) then
    objNetwork.AddWindowsPrinterConnection "\\"                                         & PrintServer & "\" & PrinterArray(3)                                     
if Err.Number Then 
wscript.echo ("Error : " & Err.Number & ": " & Err.Description & VbCrLf) 
Err.Clear 
End If 
If ImpDefault = objPrinter.Name then 
objNetwork.SetDefaultPrinter ("\\" & PrintServer & "\" & PrinterArray(3)) 
End If 
objNetwork.RemovePrinterConnection objPrinter.Name 
End If 
Next 
End If 

0 个答案:

没有答案