Re: Problem deleting a printer object
- From: "JHP" <goawayspam@xxxxxxx>
- Date: Mon, 19 Feb 2007 14:33:39 -0500
Is this what you have:
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
' Select Case rtnPrinter.PrinterStatus
' Case 1
' strPrinterStatus = "Other"
' Case 2
' strPrinterStatus = "Unknown"
' Case 3
' strPrinterStatus = "Idle"
' Case 4
' strPrinterStatus = "Printing"
' Case 5
' strPrinterStatus = "Warmup"
' Case 6
' strPrinterStatus = "Stopped printing"
' Case 7
' strPrinterStatus = "Offline"
' End Select
"JeffH" <JeffH@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:8BC4C14E-AE63-4DD0-8B7C-8E9E00A8CD50@xxxxxxxxxxxxxxxx
Hi,
I created a script with a lot of outside help that adds a printer
connection
for every user on the PC and then deletes the printer it is replacing.
After
this completes I have the script write some information to a log file.
This
is all done with the help of Active Directory and Group Policy. I'm using
the group policy 'Startup' capabilities to launch my script.
I am having one problem and that is deleting the old printer on a series
of
Windows 2000 workstations, Windows XP can handle this without a problem.
I
was hoping that someone out there might have a suggestion. I have several
dozen PCs that have a printer connection that was added to it via a Novell
Zenworks package. The problem that I am is that I cannot get the
object/method known as 'objNetwork.RemovePrinterConnection' to remove the
printer.
Does anyone have any suggestion as to how I can remove a printer
connection
in Windows 2000. My script is attached below.
Thanks,
JeffH
' ********************************************************
Option Explicit
Dim Shell, objFile, objFSO, WshNetwork
Dim objService, colServices, errReturnCode, objWMIService, strComputer
Dim colInstalledPrinters, objPrinter, objOperatingSystem,
colOperatingSystems
Const ForAppending = 8
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colOperatingSystems = objWMIService.ExecQuery _
("Select * from Win32_OperatingSystem")
Set objService = GetObject("winmgmts:")
Set Shell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set colInstalledPrinters = objWMIService.ExecQuery _
("Select * from Win32_Printer")
For Each objOperatingSystem in colOperatingSystems
If objOperatingSystem.Caption = "Microsoft Windows XP Professional"
Then
Shell.Run "rundll32.exe printui.dll,PrintUIEntry /ga
/n\\HRACCTG\is-color"
Set colServices = objService.ExecQuery _
("Select * from Win32_Service Where DisplayName = 'Print Spooler'")
For Each objService In colServices
errReturnCode = objService.StopService()
Next
WScript.Sleep 20000
For Each objService in colServices
errReturnCode = objService.StartService()
Next
For Each objPrinter in colInstalledPrinters
If objPrinter.Name = "\\IMRF\IS-COLOR-Q" Then
objPrinter.Delete_
End If
Next
ElseIf objOperatingSystem.Caption = "Microsoft Windows 2000
Professional" Then
Shell.Run "rundll32.exe printui.dll,PrintUIEntry /ga
/n\\HRACCTG\is-color"
End If
Next
'Creates a connection to a text file listing the computer name
Set WshNetwork = WScript.CreateObject ("WScript.Network")
Set objFile = objFSO.OpenTextFile("\\HRACCTG\logs\is-color.txt",
ForAppending)
objFile.Writeline WshNetwork.ComputerName & vbTab & Now
WScript.Echo "Done"
.
- Follow-Ups:
- Re: Problem deleting a printer object
- From: JeffH
- Re: Problem deleting a printer object
- References:
- Problem deleting a printer object
- From: JeffH
- Problem deleting a printer object
- Prev by Date: Re: get and save "1.jpg, 2.jpg, 3.jpg, 4.jpg, 5.jpg"
- Next by Date: Stop multiple email attachments in DO Loop
- Previous by thread: Problem deleting a printer object
- Next by thread: Re: Problem deleting a printer object
- Index(es):
Relevant Pages
|
Loading