Problem deleting a printer object



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"
.



Relevant Pages

  • RE: Printers and Faxes
    ... may deploy printers to users or computers by using Group Policy. ... the printer connection settings are applied to the users or computers ... script or to a user logon script (for ... printer connection settings will run the PushPrinterConnections.exe utility. ...
    (microsoft.public.windows.server.networking)
  • connecting to a computers local printer
    ... organizational unit to which this logon script is assigned. ... resource. ... I would like this particular computer perform the printer connection ...
    (microsoft.public.scripting.vbscript)
  • Re: printer install
    ... Adds a printer connection to a network printer. ... Script must be run on the ... local computer. ...
    (microsoft.public.scripting.vbscript)
  • Re: printer install
    ... > From MS's System Administration Scripting Guide: ... > Adds a printer connection to a network printer. ... Script must be run on the ...
    (microsoft.public.scripting.vbscript)
  • add Printer at logon
    ... Adds a Windows-based printer connection to your computer system. ... Windows NT/2000: ... String value indicating the name of the driver (ignored if used on Windows ... for the AddWindowsPrinterConnection method to work. ...
    (microsoft.public.scripting.vbscript)