JHP
Wed Apr 12 14:42:09 CDT 2006
Nice!
"maximillianx" <u1p2p3h4o5l6d72001@hotmail.com> wrote in message
news:efL%23UNmXGHA.1352@TK2MSFTNGP05.phx.gbl...
> OP stated he wanted to delete all printers from serverA - this script will
> remove all printers regardless of where they are served from.
>
> I modified your code slightly (see the IF statement) - That hopefully
> should work as well
>
> Option Explicit
>
> Dim strComputer, objWMI, objPrinter, objWSH, rtnPrinter
> Const ForceRemove = True
> Const UpdateProfile = True
>
> strComputer ="."
> Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
> Set objPrinter = objWMI.ExecQuery("SELECT * FROM Win32_Printer")
> Set objWSH = WScript.CreateObject("WScript.Network")
>
> On Error Resume Next
>
> For Each rtnPrinter In objPrinter
> If rtnPrinter.PrinterStatus = 3 and instr(rtnPrinter.DeviceID,"\\serverA")
> Then
> 'show the deviceID we are about to remove
> msgbox rtnPrinter.DeviceID
>
> objWSH.RemovePrinterConnection rtnPrinter.DeviceID, ForceRemove,
> UpdateProfile
> End If
> Next
>
> Set objWSH = Nothing
> Set objPrinter = Nothing
> Set objWMI = Nothing
>
>
> "JHP" <goawayspam@GFY.com> wrote in message
> news:Oa%23kPNlXGHA.4144@TK2MSFTNGP04.phx.gbl...
>> Option Explicit
>>
>> Dim strComputer, objWMI, objPrinter, objWSH, rtnPrinter
>> Const ForceRemove = True
>> Const UpdateProfile = True
>>
>> strComputer ="."
>> Set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
>> Set objPrinter = objWMI.ExecQuery("SELECT * FROM Win32_Printer")
>> Set objWSH = WScript.CreateObject("WScript.Network")
>>
>> On Error Resume Next
>>
>> For Each rtnPrinter In objPrinter
>> If rtnPrinter.PrinterStatus = 3 Then
>> objWSH.RemovePrinterConnection rtnPrinter.DeviceID, ForceRemove,
>> UpdateProfile
>> End If
>> Next
>> Set objWSH = Nothing
>> Set objPrinter = Nothing
>> Set objWMI = Nothing
>>
>> <bjriffel@hotmail.com> wrote in message
>> news:1144857441.759103.327070@z34g2000cwc.googlegroups.com...
>>> I'm moving our printers off the old file server and onto a new print
>>> server appliance. I'm using the scripts from this page:
>>>
>>>
http://www.microsoft.com/technet/scriptcenter/scripts/printing/client/default.mspx
>>>
>>> The problem is that I want it to delete all printer connections coming
>>> from \\serverA. And create new ones to shares on serverB. I don't
>>> mind having to specify in each script which printers to add, but I
>>> don't want to assume to know which printers the computers currently
>>> have installed. I just want to delete ALL connections to the old
>>> server.
>>>
>>> This is the script I have now, but it has to be set up knowing which
>>> printer is currently installed. And worse yet, after it runs once, the
>>> printer is deleted. Then when you run it again (at login) it gives you
>>> an error because it can't find the connection. If I could just remove
>>> the error from being displayed, then I could just list ALL of the
>>> printers from the old print server in the script and that would cover
>>> me.
>>>
>>>
>>>
>>> Set objNetwork = WScript.CreateObject("WScript.Network")
>>> objNetwork.RemovePrinterConnection "\\serverA\printer01"
>>>
>>>
>>> Set WshNetwork = CreateObject("WScript.Network")
>>>
>>> WshNetwork.AddWindowsPrinterConnection "\\serverB\printer01"
>>> WshNetwork.AddWindowsPrinterConnection "\\serverB\printer03"
>>> WshNetwork.SetDefaultPrinter "\\serverB\printer03"
>>>
>>
>>
>
>