Re: Script to remove all network printers.
From: Matt Boren (Boren_at_discussions.microsoft.com)
Date: 08/30/04
- Next message: Bad Beagle: "Password expiration"
- Previous message: Grigs: "ActiveX .CAB Download Issues"
- In reply to: Johan Arwidmark: "Re: Script to remove all network printers."
- Messages sorted by: [ date ] [ thread ]
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.
>
>
- Next message: Bad Beagle: "Password expiration"
- Previous message: Grigs: "ActiveX .CAB Download Issues"
- In reply to: Johan Arwidmark: "Re: Script to remove all network printers."
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|