Problem deleting a printer object
- From: JeffH <JeffH@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 18 Feb 2007 12:46:00 -0800
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: JHP
- Re: Problem deleting a printer object
- Prev by Date: Find computer names on network
- Next by Date: Deleting All Folders within another folder
- Previous by thread: Find computer names on network
- Next by thread: Re: Problem deleting a printer object
- Index(es):
Relevant Pages
|