#43508 - 2003-07-29 01:36 PM
removing printers
|
Jonas1
Lurker
Registered: 2003-07-29
Posts: 4
Loc: Dordrecht
|
I want to remove the 21 network printers from my profile using the following script.
break on $Index = 0 do $KeyName = ENUMKEY("HKEY_CURRENT_USER\Printers\Connections", $Index) $x=left("$KeyName",13) if $x=",,DRPDRD-KA01" Delprinterconnection ($KeyName) endif $Index = $Index + 1 ? $Index ? $x ? $KeyName
until @error <> 0
the ? are for me to see what is happening. DRPDRD-KA01 is name of printserver
The problem is that after running the script only half of the printers are removed. after running script again another 5 are removed. After 4 times in a row running the script all printers are removed why? what did i do wrong? I want it to happen running the script just once
|
|
Top
|
|
|
|
#43510 - 2003-07-29 02:18 PM
Re: removing printers
|
Jonas1
Lurker
Registered: 2003-07-29
Posts: 4
Loc: Dordrecht
|
I already tried to use the sleep, did not help Yes it is a migration to another printserver. Shall read the links you gave me
thanks for replay
Jonas
|
|
Top
|
|
|
|
#43512 - 2003-07-29 03:51 PM
Re: removing printers
|
Jonas1
Lurker
Registered: 2003-07-29
Posts: 4
Loc: Dordrecht
|
That makes sense, will try this and thanks for the advise
Jonas
|
|
Top
|
|
|
|
#43513 - 2003-07-31 12:03 AM
Re: removing printers
|
Jonas1
Lurker
Registered: 2003-07-29
Posts: 4
Loc: Dordrecht
|
Thank for the advice, i made another script which worked fine.
$Index = 0
dim $array [40]
do $KeyName = ENUMKEY("HKEY_CURRENT_USER\Printers\Connections", $Index) $array [$Index] = $KeyName $Index = $Index + 1 ? $Index until @error <> 0
$z = 0 do $x=left($array [$z],13) RedirectOutput("c:\432.txt") ? $x if $x=",,drpdrd-ka01" Delprinterconnection ($array [$z]) endif $z = $z +1 until $z = 40
the redirect and ? commands are there for me to check what is happening and can be removed
the array declaration of 40 must be changed but that is spending some more time on the script. the bottemline is that it works. refining the code is next. Problem solved. I hope that other readers got wiser by this example of registry behavior which caused my original problem
greetings Jonas
|
|
Top
|
|
|
|
#43514 - 2003-07-30 01:16 PM
Re: removing printers
|
MightyR1
MM club member
   
Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
|
Nicer code:
code:
Break on Dim $printers, $printer, $rc $printers=arrayenumkey('HKEY_CURRENT_USER\Printers\Connections') For Each $printer In $printers If InStr($printer,'DRPDRD-KA01') $printer=Split($printer,',') $printer='\\'+$printer[2]+'\'+$printer[3] ? '-I- Connection found: '+$printer $rc=DelPrinterConnection($printer) If @error ? '-E- Error deleting connection to '+$printer+' (EC='+@error+')' Else ? '-I- Succesfully deleted connection to '+$printer EndIf EndIf Next Exit ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ;Functions!!!
;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
_________________________
Greetz, Patrick Rutten
- We'll either find a way or make one... - Knowledge is power; knowing how to find it is more powerful... - Problems don't exist; they are challenges...
|
|
Top
|
|
|
|
#43515 - 2003-07-30 02:13 PM
Re: removing printers
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
Jonas,
quote:
I hope that other readers got wiser by this example of registry behavior which caused my original problem
I think the "key element" is the ARRAYENUMKEY() UDF for this issue. That is, deleting all 21 printers installed.
But, then again if you think about your initial response to me.. The Printer Migration script is even more key.
So.. That being said. Are you trying to delete all printers installed? Or, are you trying to migrate printers from one print server to another?
Kent
|
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2009 anonymous users online.
|
|
|