Re: Delete only XP printers

Tech-Archive recommends: Fix windows errors by optimizing your registry



How about something like this?

Option Explicit
On Error Resume Next

Dim strComputer, objWMIService, colOperatingSystems
Dim colInstalledPrinters, objOperatingSystem

strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer &
"\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
If objOperatingSystem.Caption = "Microsoft Windows XP Professional"
Then
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")

For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
End If
Next

YostNetSolutions wrote:
I am just starting out on this whole script thing. I would like to have a
scrip that determines the OS type and then if it is XP delete the printers.
I have found two scripts. One displays the OS type, the other deletes the
local printers.

Display the OS
------------------------------------------------------------------------------------------------
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")


Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
msg = objOperatingSystem.Caption
msgbox msg
Next
------------------------------------------------------------------------------------------------

The other deletets all the printers.

------------------------------------------------------------------------------------------------
On Error Resume Next
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
------------------------------------------------------------------------------------------------

I know I just need to put something like: If colOperatingSystems =
"Microsoft Windows XP Professional" in there and take out the Msg lines. So I
would have something like:
------------------------------------------------------------------------------------------------
'On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")

Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")


If colOperatingSystems <> "Microsoft Windows XP Professional" Then
For Each objPrinter in colInstalledPrinters
objPrinter.Delete_
Next
Else
'do nothing
End if

.



Relevant Pages

  • Re: Automatisches Beenden von Programmen beim Herunterfahren
    ... Set colOperatingSystems = objWMIService.ExecQuery _ ... For Each objOperatingSystem in colOperatingSystems ...
    (microsoft.public.de.german.windowsxp.sonstiges)
  • Re: =?ISO-8859-1?Q?=5FShutdown=5F=FCber=5FTaskplaner?=
    ... *Administrator* ist, nicht als eingeschränkter Benutzer. ... Set colOperatingSystems = objWMIService.ExecQuery _ ... For Each objOperatingSystem in colOperatingSystems ...
    (microsoft.public.de.german.windowsxp.setup)
  • Re: Delete only XP printers
    ... Dim strComputer, objWMIService, colOperatingSystems ... Dim colInstalledPrinters, objOperatingSystem, msg, objPrinter ...
    (microsoft.public.scripting.vbscript)
  • Re: Delete only XP printers
    ... Dim strComputer, objWMIService, colOperatingSystems ... Dim colInstalledPrinters, objOperatingSystem, msg, objPrinter ...
    (microsoft.public.scripting.vbscript)
  • Re: Delete only XP printers
    ... Dim strComputer, objWMIService, colOperatingSystems ... Dim colInstalledPrinters, objOperatingSystem, msg, objPrinter ...
    (microsoft.public.scripting.vbscript)