#142943 - 2005-07-06 08:02 AM
Re: delete all printers before connecting new ones
|
Kat
Fresh Scripter
Registered: 2005-06-22
Posts: 15
Loc: Melbourne - Australia
|
All what counts to me is that it is working now. and that you guys are able to help. I still have so many other thinks to solve that everything which works is good!
Kat
|
Top
|
|
|
|
#142944 - 2005-07-06 09:20 AM
Re: delete all printers before connecting new ones
|
Richard H.
Administrator
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
got it going! All I needed to change on your function was the counter. It seems like the key numbering are going in .5 steps and not in 1. Therfore every second printer was skiped. I changed your counter $c=$c+0.5 and it works perfectly!
Because $c is an integer the "0.5" is cast to a value of "0", so your statment becomes $c = $c + 0 - don't worry too much though, because this is what you want.
Jooel has fixed the UDF in the UDF forum, I recommend that you get his updated version.
|
Top
|
|
|
|
#142948 - 2006-08-25 05:06 AM
Re: delete all printers before connecting new ones
|
saamwan
Lurker
Registered: 2006-08-25
Posts: 2
|
This worked really well except that it wont delete printers with names over 13 characters can you suggest how to modify the script for these
|
Top
|
|
|
|
#142949 - 2006-08-25 08:27 AM
Re: delete all printers before connecting new ones
|
Greg_Wilson
Fresh Scripter
Registered: 2006-08-25
Posts: 8
|
I've just tried this code in a MS 2003 terminal server environment and am having exactly the same intermittent result as delprinterconnection("").
The script works reliably when called from a mapped drive in a TS session but doesn't remove printers when run as a login script.
Any tips? I'm mystified.
Thanks,
Greg.
|
Top
|
|
|
|
#197677 - 2010-02-04 05:53 PM
Re: delete all printers before connecting new ones
[Re: Les]
|
bertus02
Just in Town
Registered: 2010-02-04
Posts: 3
Loc: Grand Rapids, MI USA
|
Hello all, I am in the middle of a migration and can't seem to get the scripting to work to delete all network printers. this is what I have any help would be greatlly appreciated....
IF INGROUP("Domain Users")
function DelPrinterConnections() dim $c,$bk,$conn $c=0 $bk="HKEY_CURRENT_USER\Printers\Connections" $conn=enumkey($bk,$c) while @error=0 $c=$c+0.5 $conn=delkey($bk+"\"+$conn) $conn=enumkey($bk,$c) loop endfunction
ENDIF
Thanks again
|
Top
|
|
|
|
#197679 - 2010-02-04 06:09 PM
Re: delete all printers before connecting new ones
[Re: bertus02]
|
Glenn Barnas
KiX Supporter
Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
|
Welcome to KORG!
This won't work as written.
You are enumerating a list of objects (registry keys representing printers). The enumeration pointer ($C) is incremented each time. When you delete a key, they all shift down a position, so this method never points to all values.
To illustrate this, put 5 coins on your desk, lined up in a row. Point to the first coin with a pen - this represents the enumeration pointer $C.
Since the pen is pointing to a coin, we remove (delete) it and move the pointer to the next position. Point to the second coin, remove the first coin, but then move the 4 remaining coins into the original location. Your pointer has now moved past the first position, where the second value now exists.
The solution is to enumerate all of the keys into an array, and then loop throuth the array to delete the values.Function DelPrinters()
Dim $aPrinters[0] ; array of connections to delete
Dim $P, $A ; pointers
Dim $Key ; reg key
Dim $Tmp ; tmp var
Dim $Rv ; Return Value
$A = -1
$P = 0
$Key = 'HKCU\Printers\Connections'
$Tmp = EnumKey($Key, $P)
If $Tmp ; at least one printer?
While Not @ERROR
$A = $A + 1
ReDim Preserve $aPrinters[$A]
$aPrinters[$A] = $Tmp
$P = $P + 1
$Tmp = EnumKey($Key, $P)
Loop
For Each $P in $aPrinters
'delete ' $Key '\' $P ?
;$Rv = DelKey($Key + '\' + $P)
Next
EndIf
EndFunction Note that as shown above, it displays what it will delete without deleting. After confirming it does what you want, comment the message line and uncomment the DelKey line.
Glenn
_________________________
Actually I am a Rocket Scientist!
|
Top
|
|
|
|
#197680 - 2010-02-04 06:53 PM
Re: delete all printers before connecting new ones
[Re: Glenn Barnas]
|
bertus02
Just in Town
Registered: 2010-02-04
Posts: 3
Loc: Grand Rapids, MI USA
|
wow! i appreciate the prompt respose. you guys rule. however the script did not work and the reg keys remain.. here is what i have
IF INGROUP("Domain Users")
Function DelPrinters()
Dim $aPrinters[0] ; array of connections to delete Dim $P, $A ; pointers Dim $Key ; reg key Dim $Tmp ; tmp var Dim $Rv ; Return Value
$A = -1 $P = 0
$Key = 'HKCU\Printers\Connections' $Tmp = EnumKey($Key, $P) If $Tmp While Not @ERROR $A = $A + 1 ReDim Preserve $aPrinters[$A] $aPrinters[$A] = $Tmp $P = $P + 1 $Tmp = EnumKey($Key, $P) Loop
For Each $P in $aPrinters 'delete ' $Key '\' $P ? $Rv = DelKey($Key + '\' + $P) Next
EndIf
EndFunction
ENDIF
|
Top
|
|
|
|
#197682 - 2010-02-04 07:17 PM
Re: delete all printers before connecting new ones
[Re: Glenn Barnas]
|
bertus02
Just in Town
Registered: 2010-02-04
Posts: 3
Loc: Grand Rapids, MI USA
|
wow! you trully are a lifesaver!
|
Top
|
|
|
|
#206560 - 2013-01-15 09:15 PM
Re: delete all printers before connecting new ones
[Re: Glenn Barnas]
|
LeRoy
Just in Town
Registered: 2009-04-30
Posts: 1
Loc: Lakemoor, IL
|
I see that the script deletes the registry keys, thus deleting the printers from the printer list.
How does this compare to the delPrinterConnection ("\\Server\Printer") command instead? Are they both doing the same thing? How would you go about delete Local TCP/IP Port Mapped printers?
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 918 anonymous users online.
|
|
|