Page 1 of 1 1
Topic Options
#204356 - 2012-02-28 07:27 AM Some Printer Help Please
Dariusvw Offline
Fresh Scripter

Registered: 2012-02-11
Posts: 11
Loc: South Africa
Greetings

I have chosen to use this rather simple code to add printers

 Code:
If InGroup("PUPIL") > 0
delprinterconnection ("\\Mars\FinanceLW") = 0
	If AddPrinterConnection ("\\Zeus\AficioC") = 0
	EndIf
	If AddPrinterConnection ("\\Zeus\AficioB") = 0
	EndIf
	;If AddPrinterConnection ("\\Mars\FinanceLW") = 0
	;EndIf
SetDefaultPrinter ("\\Zeus\Aficio (Mono)")
EndIf


The "\\Mars\FinanceLW" printer was added so that i could test the removing of all printers before new ones are added.

Problem is I cannot get it to remove ALL printers 1st.
I have tried
delprinterconnection () = 0
and
delprinterconnection ("") = 0

Neither of which work. Yet i have seen both suggested on the forum.

Am I missing something?
Thanks

Top
#204357 - 2012-02-28 09:17 AM Re: Some Printer Help Please [Re: Dariusvw]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
Maybe an enumeration of all printers can help you?
Copy and paste the following function in your code.
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=138355
 Code:
Dim $RC
Dim $Printers, $Printer
$Printers = EnumPrinterConnections2()
For Each $Printer in $Printers
	;? $Printer
	$Printer = Split($Printer, ',')[0]
	;? $Printer
	$RC = DelPrinterConnection($Printer)
Next

To speed up the login script, I would advise to always check if the printer has been added before. PriMapState() can help you:
http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=83306

Top
#204358 - 2012-02-28 09:27 AM Re: Some Printer Help Please [Re: Dariusvw]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
This should do the trick.

 Code:
$key = "HKCU\Printers\Connections"
;Enumerate network printers key.
$oldprinters = ArrayEnumKey($key)

For Each $oldprinter in $oldprinters
	;Replace every comma with a backslash
	$oldprinter = Join(Split($oldprinter, ","), "\")
	;Delete each printer that should be deleted.
	$rc = DelPrinterConnection($oldprinter)
Next


;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
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#204359 - 2012-02-28 09:29 AM Re: Some Printer Help Please [Re: Witto]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
LOL
Did not even see your post Witto. Looks like we had the same idea but a slightly different solution.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#204360 - 2012-02-28 10:26 AM Re: Some Printer Help Please [Re: Mart]
Witto Offline
MM club member
*****

Registered: 2004-09-29
Posts: 1828
Loc: Belgium
I presume this should help to speed up te logon script (I did not test it).
Grabbing the output of the used functions in variables avoids command screen output and enables you using wkix32.exe
 Code:
Dim $RC
Dim $Printers, $Printer
$Printers = EnumPrinterConnections2()
For Each $Printer in $Printers
	;? $Printer
	$Printer = Split($Printer, ',')[0]
	;? $Printer
	;$RC = DelPrinterConnection($Printer)
Next

If PriMapState('\\Zeus\AficioC') = ''
	$RC = AddPrinterConnection('\\Zeus\AficioC')
EndIf
If PriMapState('\\Zeus\AficioB') = ''
	$RC = AddPrinterConnection('\\Zeus\AficioB')
EndIf
;If PriMapState('\\Mars\FinanceLW') = ''
;	$RC = AddPrinterConnection('\\Mars\FinanceLW')
;EndIf
If PriMapState('\\Zeus\Aficio (Mono)') = ''
	$RC = AddPrinterConnection('\\Zeus\Aficio (Mono)')
EndIf
If Not PriMapState('\\Zeus\Aficio (Mono)') = 2
	$RC = SetDefaultPrinter('\\Zeus\Aficio (Mono)')
EndIf

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 2312 anonymous users online.
Newest Members
fgarcia, Viginette, ManuvdWielNL, Sir_Barrington, batdk82
17889 Registered Users

Generated in 0.057 seconds in which 0.028 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