Re: Script to remove all network printers.

From: Matt Boren (Boren_at_discussions.microsoft.com)
Date: 08/30/04


Date: Mon, 30 Aug 2004 11:55:03 -0700

This works on WindowsXP, but fails on Win2000 Pro. It returns "SWbemObject:
Provider is not capable of the attempted operation".

After trying a few different ways, I read that "Instances of Win32_Printer
are read-only" for Win2000 and WinNT 4 (from
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/swbemobject_delete_.asp).
 This seems to be causing the ".Delete_" method to fail. Does anyone know a
way to get around the read-only attrib of a Win32_Printer instance on Win2000?

Thanks,

Matt Boren
Systems Admin I

"Johan Arwidmark" wrote:

> ' Delete all local printers
>
> strComputer = "."
>
> Set objWMIService = GetObject("winmgmts:" & _
> "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
>
> Set colInstalledPrinters = objWMIService.ExecQuery & _
> ("Select * from Win32_Printer")
>
> For Each objPrinter in colInstalledPrinters
> objPrinter.Delete_
> Next
>
>
>
> regards
> Johan Arwidmark
>
> Windows User Group - Nordic
> http://www.wug-nordic.net
>
>
> On Wed, 11 Aug 2004 16:21:02 -0700, Tom Jones <Blah@blah.com> wrote:
>
> >Hi there,
> > We are trying to allocate printers by OU. We have loopback enabled on a
> >group policy and it runs the following script:
> >
> >Set WshNetwork =CreateObject("WScript.Network")
> >PrinterPath ="\\servername\HP4300n"
> >WshNetwork.AddWindowsPrinterConnection PrinterPath
> >WshNetwork.SetDefaultPrinter PrinterPath
> >
> >That scripts works excellently for connecting to a shared printer and
> >setting it as default, but it leaves existing printers connected. In a
> >school, that is not desirable as kids will be printing to different rooms. I
> >wish to insert a line in the above script that will delete ALL existing
> >printers before setting the 'proper' default one. I presume that I need to
> >use the 'RemovePrinterConnection' property, but I don't know how to use it
> >when you don't actually know the name of the printer you want to disconnect.
> >
> >Any help would be greatly appreciated.
> >Thanks.
>
>



Relevant Pages

  • Re: When Virtual Print Server fails over it corrupts client drivers
    ... I'll just have to wait till it fails over to ... Chuck Timon, Jr. ... They are on the virtual server not the node. ... The printers are in start run \\ahtprntvs01 ...
    (microsoft.public.windows.server.clustering)
  • Re: When Virtual Print Server fails over it corrupts client drivers
    ... Chuck Timon, Jr. ... They are on the virtual server not the node. ... > The printers are in start run \\ahtprntvs01 ... > The issue is that when the virtual server fails over then fails back, ...
    (microsoft.public.windows.server.clustering)
  • Re: When Virtual Print Server fails over it corrupts client drivers
    ... Were added using print management on a R2 server connected to the ... They are on the virtual server not the node. ... The printers are in start run \\ahtprntvs01 ... The issue is that when the virtual server fails over then fails back, ...
    (microsoft.public.windows.server.clustering)
  • RE: Some Printers not Rolling over when Cluster Fails -
    ... Have you tried increasing the Quorum Log Size? ... Some Printers not Rolling over when Cluster Fails - ... > our services one of them being Printing - we have about 100 printers on this ... A handful of printers don't roll over. ...
    (microsoft.public.windows.server.clustering)
  • Re: pushprinterconnection.exe
    ... You said you used a startup script right? ... Since startup scripts (versus ... In the Group Policy Object Editor: ... Logged on as administrator and didn't get the assigned printers. ...
    (microsoft.public.windows.group_policy)