Re: Problem deleting a printer object



Hi,

I tested out the script suggested by JHP. It doesn't do the trick. Does
anyone else have a suggestion on what I can do. I'm thinking that my only
alternative is to delete all of the registry emtries that were made regarding
this printer. Does anyone know if there is a central location in the Windows
2000 environment where the printer definitions are stored?

Thanks,
JeffH

"JeffH" wrote:

Hi JHP,

I'll have to give this a try. It might just work.

Thanks,
JeffH

"JHP" wrote:

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"



.



Relevant Pages

  • Re: Problem deleting a printer object
    ... You may want to check the version of Windows Script... ... For Each objPrinter in colInstalledPrinters ... Dim strComputer, objWMI, objPrinter, objWSH, rtnPrinter ...
    (microsoft.public.scripting.vbscript)
  • Re: Problem deleting a printer object
    ... the script appears to be working but when I go to ... You may want to check the version of Windows Script... ... For Each objPrinter in colInstalledPrinters ... Dim strComputer, objWMI, objPrinter, objWSH, rtnPrinter ...
    (microsoft.public.scripting.vbscript)
  • Re: Problem deleting a printer object
    ... Try putting this in a .vbs file and running it directly on the Windows 2000 ... For Each objPrinter in colInstalledPrinters ... I tested out the script suggested by JHP. ... Dim strComputer, objWMI, objPrinter, objWSH, rtnPrinter ...
    (microsoft.public.scripting.vbscript)
  • Re: Problem deleting a printer object
    ... Try putting this in a .vbs file and running it directly on the Windows 2000 ... For Each objPrinter in colInstalledPrinters ... I tested out the script suggested by JHP. ... Dim strComputer, objWMI, objPrinter, objWSH, rtnPrinter ...
    (microsoft.public.scripting.vbscript)
  • Re: Microsoft Warns of New Windows Flaw (March 19, 2003 )
    ... In WINDOWS SETUP in ADD/REMOVE PROGRAMS of Control Panel ... Uninstall Outlook Express, ... Java, Javascript, ActiveX and all the other script runner toys Billy ... Install WebWasher the spammers are terrified of free from ...
    (comp.security.misc)