Adding a new printer share then remove old
- From: "VKIT" <VKIT@xxxxxxxxxxxx>
- Date: Mon, 3 Oct 2005 17:41:43 -0500
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
.
- Prev by Date: Re: Sorting strings in vbscript
- Next by Date: Re: Dynamic Window/Control Updates
- Previous by thread: Editing a GPO
- Next by thread: Re: Dynamic Window/Control Updates
- Index(es):
Relevant Pages
|