B
bolzy1981@gmail.com
Guest
Hello,
I'd like to modify this script I found on the web so that it will not
remove any printers attached to the print servers other than the one
specified in the script, this is an example of what I want it to do
Scenario:
3 Print Servers
- Print1
- Print1A
- Print2
Client PC has 3 printers installed
- P001 on server Print1
- P002 on server Print1
- P010 on server Print2
Action:
How would I modify the below script so that it only removes the
printers from server Print1, and readds them from server Print1A -
leaving any printers that are attached to server Print2
=========================================
On Error Resume Next
'Creates variables for querying the default printer
Function GetDefaultPrinter()
sRegVal = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows
\Device"
sDefault = ""
'Queries the registry for the default printer
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")
strComputer = "."
PrintServer = "Print1A"
PrintServer = LCase (PrintServer)
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
=========================================
Thanks,
Marcus
I'd like to modify this script I found on the web so that it will not
remove any printers attached to the print servers other than the one
specified in the script, this is an example of what I want it to do
Scenario:
3 Print Servers
- Print1
- Print1A
- Print2
Client PC has 3 printers installed
- P001 on server Print1
- P002 on server Print1
- P010 on server Print2
Action:
How would I modify the below script so that it only removes the
printers from server Print1, and readds them from server Print1A -
leaving any printers that are attached to server Print2
=========================================
On Error Resume Next
'Creates variables for querying the default printer
Function GetDefaultPrinter()
sRegVal = "HKCU\Software\Microsoft\Windows NT\CurrentVersion\Windows
\Device"
sDefault = ""
'Queries the registry for the default printer
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")
strComputer = "."
PrintServer = "Print1A"
PrintServer = LCase (PrintServer)
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
=========================================
Thanks,
Marcus