Login | |
|
 |
Re: Delete local printers using a script - 8/3/2004 11:07:13 AM
|
|
 |
|
| |
mbouchard
Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
Try WMI. I used tested this script and deleted a local printer strComputer = "." Set objWMIService = GetObject("winmgmts:" _ & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colInstalledPrinters = objWMIService.ExecQuery _ ("Select * from Win32_Printer where DeviceID = 'hp 2000c'") For Each objPrinter in colInstalledPrinters objPrinter.Delete_ Next
|
|
| |
|
|
|
 |
Re: Delete local printers using a script - 8/4/2004 5:14:17 AM
|
|
 |
|
| |
mbouchard
Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
Did you change the device ID to equal your printer?
|
|
| |
|
|
|
 |
Re: Delete local printers using a script - 8/5/2004 12:35:41 AM
|
|
 |
|
| |
mbouchard
Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
Not really sure why this is but, I tested your script at work and it failed for me (Worked at home) then I got to looking in script center. After running some tests I copied the script from Script Center and put in my test local printer (LPT1) and it worked. I then began comparing the script you posted and the one from SC and found 1 difference. Yours was missing the _ at the end of the delete line. Try changing objPrinter.Delete to objPrinter.Delete_ and it should work. I tested it and it worked for me. Mike
|
|
| |
|
|
|
 |
Re: Delete local printers using a script - 8/5/2004 5:25:56 AM
|
|
 |
|
| |
mbouchard
Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
Was the Provider error for the line that contained the delete?
|
|
| |
|
|
|
 |
Re: Delete local printers using a script - 8/6/2004 12:10:19 AM
|
|
 |
|
| |
mbouchard
Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
|
Zen, Yes, you would need to delete all the subkeys to delete a regkey. Here is a script that we use at work to delete regkeys and their subkeys. Const HKEY_CURRENT_USER = &H80000001 Dim oReg Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\default:StdRegProv") Call DelRegKey(oReg, HKEY_CURRENT_USER, "Software\Microsoft\OfficeCustomizeWizard") Msgbox "Completed" Sub DelRegKey(oReg, Key, sSubkey) ' Deletes registry key and subkeys (permissions to delete keys must exist) ' Key: Tree that contains the sSubKey path ' (HKEY_CLASSES_ROOT, HKEY_CURRENT_USER, HKEY_LOCAL_MACHINE, HKEY_USERS or HKEY_CURRENT_CONFIG) ' sSubkey: Subkey to be deleted (Case-sensitive string) ' (Example: "SOFTWARE\System Admin Scripting Guide") Dim aSubkeys, subkey oReg.EnumKey Key, sSubkey, aSubkeys If Not IsNull(aSubKeys) Then For Each subkey In aSubkeys Call DelRegKey(oReg, Key, sSubKey & "\" & subkey) Next End If ' Error trapping in case we can't delete (no permissions) On Error Resume Next oReg.DeleteKey Key, sSubKey On Error GoTo 0 End Sub
|
|
| |
|
|
|
|
|