Removing All Printers Reguardless of name

calvinj

[H]ard|Gawd
Joined
Mar 2, 2009
Messages
1,738
We are going to be renaming some printers at the office where I'm at. The intention is to take a vb script and run it each time the user logs in and it will map the most appropriate printer for their location.

here is the question. I know you can do a net use * /delete, but can i do the same thing for printers?
 

calvinj

[H]ard|Gawd
Joined
Mar 2, 2009
Messages
1,738
Found a Kixtart Script that worked. The link provided just doesn't work

Code:
If Not @LOGONMODE
	Break on
EndIf

;======== Delete all network printers ========
;Delete all mapped network printers
$key = "HKEY_CURRENT_USER\Printers\Connections"
$printers = ArrayEnumKey($key)
For Each $printer in $printers
	$rc = DelKey($key + "\" + $printer)
Next


; DO NOT MODIFY ANYTHING BELOW THIS LINE.
; THIS IS A UDF AND IT IS READY MADE AS IT IS.

;NAME          ArrayEnumKey
;
;ACTION        Creates an array of names of the subkeys contained in a registry key or subkey
;
;AUTHOR        Jens Meyer (sealeopard@usa.net)
;
;VERSION       1.2 (added error codes)
;              1.1
;
;DATE CREATED  2001/12/05
;
;DATE MODIFIED 2003/05/17
;
;KIXTART       4.12+
;
;SYNTAX        ARRAYENUMKEY($subkey)
;
;PARAMETERS    SUBKEY
;              Required string containing the key or subkey for which the subkeys will be enumerated
;
;RETURNS       Array containing the subkeys
;
;REMARKS       none
;
;DEPENDENCIES  none
;
;EXAMPLE       $retcode=arrayenumkey('HKEY_USERS')
;
;KIXTART BBS   http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=12&t=000064
;
Function arrayenumkey($regsubkey)
  Dim $retcode, $subkeycounter, $currentsubkey, $subkeyarray

  If Not KeyExist($regsubkey)
    Exit 87
  EndIf

  $subkeycounter=0
  Do
    $currentsubkey=EnumKey($regsubkey,$subkeycounter)
    If Not @ERROR
      ReDim preserve $subkeyarray[$subkeycounter]
      $subkeyarray[$subkeycounter]=$currentsubkey
      $subkeycounter=$subkeycounter+1
    EndIf
  Until @ERROR

  $arrayenumkey=$subkeyarray
  Exit 0
EndFunction

The nice this is that this will not remove local printers (lpt, usb, network printers added locally)

Hope this helps someone
 
Top