Every network admin has had to remove a print server from their environment and set up a new one. While installing a print server can be tedious job. the worst part for me has always been updating the installed printers on all of my clients.  well with this little vbscript it is no problem at all!

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 = “NEW PRINT SERVER NAME HERE”
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

By admin


Deprecated: Return type of Requests_Cookie_Jar::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/mcgeary/public_html/wp-includes/Requests/Cookie/Jar.php on line 63

Deprecated: Return type of Requests_Cookie_Jar::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/mcgeary/public_html/wp-includes/Requests/Cookie/Jar.php on line 73

Deprecated: Return type of Requests_Cookie_Jar::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/mcgeary/public_html/wp-includes/Requests/Cookie/Jar.php on line 89

Deprecated: Return type of Requests_Cookie_Jar::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/mcgeary/public_html/wp-includes/Requests/Cookie/Jar.php on line 102

Deprecated: Return type of Requests_Cookie_Jar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/mcgeary/public_html/wp-includes/Requests/Cookie/Jar.php on line 111

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetExists($key) should either be compatible with ArrayAccess::offsetExists(mixed $offset): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/mcgeary/public_html/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 40

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetGet($key) should either be compatible with ArrayAccess::offsetGet(mixed $offset): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/mcgeary/public_html/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 51

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetSet($key, $value) should either be compatible with ArrayAccess::offsetSet(mixed $offset, mixed $value): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/mcgeary/public_html/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 68

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::offsetUnset($key) should either be compatible with ArrayAccess::offsetUnset(mixed $offset): void, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/mcgeary/public_html/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 82

Deprecated: Return type of Requests_Utility_CaseInsensitiveDictionary::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /home/mcgeary/public_html/wp-includes/Requests/Utility/CaseInsensitiveDictionary.php on line 91