Page 2 of 2 <12
Topic Options
#142942 - 2005-07-06 06:06 AM Re: delete all printers before connecting new ones
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
wow.
and this was not fixed 2 years ago when the UDF was really used?

kat, good to hear it works.
still, it's an issue of kix and it makes me worry.
_________________________
!

download KiXnet

Top
#142943 - 2005-07-06 08:02 AM Re: delete all printers before connecting new ones
Kat Offline
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 Offline
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
#142945 - 2005-07-06 09:50 AM Re: delete all printers before connecting new ones
Kat Offline
Fresh Scripter

Registered: 2005-06-22
Posts: 15
Loc: Melbourne - Australia
Good idea, done that and it works,
thanks all for your help - I am sure I'll be back!
Kat

Top
#142946 - 2005-07-09 10:17 PM Re: delete all printers before connecting new ones
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
It has to do with increasing the index in ENUMKEY if the current key is being deleted. That results in the next key moving up one index, thus becoming the current key still under the current index. This is basic ENUM functionality!
_________________________
There are two types of vessels, submarines and targets.

Top
#142947 - 2005-07-09 11:11 PM Re: delete all printers before connecting new ones
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
that is, but if the udf has worked before, this enum functionality has changed at some point.
_________________________
!

download KiXnet

Top
#142948 - 2006-08-25 05:06 AM Re: delete all printers before connecting new ones
saamwan Offline
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 Offline
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
#142950 - 2006-08-25 09:07 AM Re: delete all printers before connecting new ones
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Are you certain the login script is running?

Are you running login scripts synchronously?

Try adding debug code to ensure that the printers are being enumerated.

Top
#142951 - 2006-08-25 05:07 PM Re: delete all printers before connecting new ones
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
and try posting to your own thread...
Top
#197677 - 2010-02-04 05:53 PM Re: delete all printers before connecting new ones [Re: Les]
bertus02 Offline
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 Administrator Offline
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.
 Code:
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! \:D

Top
#197680 - 2010-02-04 06:53 PM Re: delete all printers before connecting new ones [Re: Glenn Barnas]
bertus02 Offline
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
#197681 - 2010-02-04 07:03 PM Re: delete all printers before connecting new ones [Re: bertus02]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
You aren't calling the function!
 Code:
If InGroup('this group')
  DelPrinters() ; call the function
EndIf

Function DelPrinters()  ; define the function
  ; code goes here...
EndFunction
You DEFINE the function at the beginning or end of your main code, then you CALL the functions in your main code, as I've illustrated above.

A common mistake. \:\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197682 - 2010-02-04 07:17 PM Re: delete all printers before connecting new ones [Re: Glenn Barnas]
bertus02 Offline
Just in Town

Registered: 2010-02-04
Posts: 3
Loc: Grand Rapids, MI USA
wow! you trully are a lifesaver!
Top
#197683 - 2010-02-04 07:30 PM Re: delete all printers before connecting new ones [Re: bertus02]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4396
Loc: New Jersey
 Originally Posted By: bertus02
wow! you trully are a lifesaver!
Yup - Butter-Rum if I had a choice! \:\)

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#206560 - 2013-01-15 09:15 PM Re: delete all printers before connecting new ones [Re: Glenn Barnas]
LeRoy Offline
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
Page 2 of 2 <12


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 248 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.136 seconds in which 0.055 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org