Page 1 of 1 1
Topic Options
#189682 - 2008-09-16 09:50 AM Function Delprinterconnections from udf doesn't work?
bjpdekker Offline
Just in Town

Registered: 2008-09-16
Posts: 3
Hello,

I want to use the Delprinterconnection which is written in the UDF.
But when i use this script it seems to do nothing.

I have a Windows 2003 Ent.Ed. R2 X64 Server, Windows XP Sp2 Workstation and KiX2010 4.6.
The AddPrinterConnection does work fine but when i use the delprinterconnection in the UDF, the result in the console =0 but none of the printers are removed from the list.

The testuser has the right to delete regkeys and the gpo allows deletion of printers.

Please can anyone tell me how to solve this issue.

Greetings,

Bas

Top
#189683 - 2008-09-16 10:12 AM Re: Function Delprinterconnections from udf doesn't work? [Re: bjpdekker]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Hi and welcome to the board.

Are you using the UDF or the build in function? The UDF is called DelprinterconnectionS and not Delprinterconnection.

Can you post the code you have so far? This way we can help you much better then when we have to guess what you script looks like.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#189684 - 2008-09-16 10:15 AM Re: Function Delprinterconnections from udf doesn't work? [Re: Mart]
bjpdekker Offline
Just in Town

Registered: 2008-09-16
Posts: 3
Function DelPrinterConnections()
Dim $bk,$conn
$bk="HKEY_CURRENT_USER\Printers\Connections"
Do
$conn=DelKey($bk+"\"+EnumKey($bk,0))
Until @error
EndFunction


This is it

Top
#189685 - 2008-09-16 10:26 AM Re: Function Delprinterconnections from udf doesn't work? [Re: bjpdekker]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Ok, that doesn't cut it.
Have a look at the example below. It should work just fine. I personally prefer a different approach as shown in teh second example. Basically is does the same it’s just matter of going left or right around and still ending up in the same place. Use whatever feels best.

 Code:
Break on

$rc =  DelPrinterConnections()


;=-=-=-=-=-=-=-=-= DO NOT MODIFY ANYTHING BELOW THIS LINE =-=-=-=-=-=-=-=-=
;=-=-=-=-=-=-=-=-= THIS IS A UDF AND IT IS READY AS IT IS NOW =-=-=-=-=-=-=-=-=
;Function:
;        DelPrinterConnections()
;
;Author:
;        Lonkero
;
;Version:
;        1.1
;
;Version History:
;        1.0 - Fri Jan 24 2003 - old enumkey code that failed every second printer
;
;Action:
;        deletes current printer connections
;
;Syntax:
;        Delprinterconnections
;
;Remarks:
;        written for kix versions that does not support delprinterconnection("")
;
;Example:
;        "unmapping printers..."
;        DelPrinterConnections
;        ? "Done."
;
;Source:
Function DelPrinterConnections() 
Dim $bk,$conn 
 $bk="HKEY_CURRENT_USER\Printers\Connections" 
 Do
  $conn=DelKey($bk+"\"+EnumKey($bk,0))
 Until @error
EndFunction



 Code:
;======== 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 AS IT IS NOW =-=-=-=-=-=-
;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


KiXtart FAQ & How to's » How to use UDFs
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#189686 - 2008-09-16 10:38 AM Re: Function Delprinterconnections from udf doesn't work? [Re: Mart]
bjpdekker Offline
Just in Town

Registered: 2008-09-16
Posts: 3
it works!

I've made an error calling the function.
Thank you very much for showing me!

greets,

Bas

Top
#189687 - 2008-09-16 10:38 AM Re: Function Delprinterconnections from udf doesn't work? [Re: bjpdekker]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Cool
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


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

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

Generated in 0.052 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

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