Re: Delete only XP printers
- From: "joseomjr@xxxxxxxxx" <joseomjr@xxxxxxxxx>
- Date: 21 Jul 2006 07:13:38 -0700
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
.
- Follow-Ups:
- Re: Delete only XP printers
- From: YostNetSolutions
- Re: Delete only XP printers
- Prev by Date: RE: Remote system restart
- Next by Date: Re: Calling csv file
- Previous by thread: Re: How to Modify Password Expire date for AD User account
- Next by thread: Re: Delete only XP printers
- Index(es):
Relevant Pages
|