Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Adding a new printer share then remove old

0 views
Skip to first unread message

VKIT

unread,
Oct 3, 2005, 6:46:21 PM10/3/05
to
The situation I'm in is we are renaming all our printers and shares. I have
used in the past a script that checks for the old printer, installs the new
one, checks for if it was a default then deletes the old. Unfortunately
this was when we where changing server names and the difference is we are
keeping the same server name but changing the printer names and shares.
However I can't seem to get this script working because the old printer name
no longer exists because it has been renamed. Is there a way around this?
Below I have a copy of our test script

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")


For Each objPrinter in colPrinters

on error resume next

If Lcase(objPrinter.name) = Lcase("\\appprint\test1") Then
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\appprint\testprint1"


Else


If Lcase(objPrinter.name) = Lcase("\\appprint\test2") Then
Set objNetwork = CreateObject("WScript.Network")
objNetwork.AddWindowsPrinterConnection "\\appprint\testprint2"


End If

End If

Next

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer Where
Default = TRUE")


For Each objPrinter in colPrinters

If Lcase(objPrinter.name) = Lcase("\\appprint\test1") Then
Set objNetwork = CreateObject("WScript.Network")
objNetwork.SetDefaultPrinter "\\appprint\testprint1"


Else

If Lcase(objPrinter.name) = Lcase("\\appprint\test2") Then
Set objNetwork = CreateObject("WScript.Network")
objNetwork.SetDefaultPrinter "\\appprint\testprint2"

End If

End If

Next

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colPrinters = objWMIService.ExecQuery("Select * From Win32_Printer")

For Each objPrinter in colPrinters

on error resume next

If Lcase(objPrinter.name) = Lcase("\\appprint\testprint1") Then
Set objNetwork = CreateObject("Wscript.Network")
objNetwork.RemovePrinterConnection "\\\appprint\test1"

Else

If Lcase(objPrinter.name) = Lcase("\\appprint\testprint2") Then
Set objNetwork = CreateObject("Wscript.Network")
objNetwork.RemovePrinterConnection "\\appprint\test2"

End If

End If

Next


0 new messages