Page 1 of 1 1
Topic Options
#175962 - 2007-05-04 10:22 AM Function EnumPrinterConnections2() gives only Novell printer
vroedie Offline
Fresh Scripter

Registered: 2006-10-05
Posts: 30
Hi,

We're fasing out Novell and therefore I am trying to construct a script that maps new windows printers, reads the default (Novell) printer, tries to reset the default printer from novell to windows and then deletes the novell printers.

I have come so far as to connect the new windows printers and read the default printer. Now I've found the EnumPrinterConnections UDF and was trying to read the installed printers. The problem that I'm having now is that the function detects some local printers (CutePDF printer) and than only detects the Novell printers even though 20 windows printers have been installed. When I remove the Novell printers manually, the UDF does detect the windows printers.

regards,

jeroen

Top
#175963 - 2007-05-04 10:58 AM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: vroedie]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I think what you are wanting is really:
http://www.kixtart.org/UDF/UDF_lister.php?what=post&code=84385

Printerlist() UDF.
the enumprinterconnections are wsh stuff.
_________________________
!

download KiXnet

Top
#175965 - 2007-05-04 11:40 AM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: Lonkero]
vroedie Offline
Fresh Scripter

Registered: 2006-10-05
Posts: 30
Hi,

sorry, still only displays the novell printer.
bugger... ;\)

Top
#175968 - 2007-05-04 12:07 PM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: vroedie]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you could also try the priMapState()

it plays directly with the registry.
only problem with it, is that it does not provide you the list but you need to provide the printer data and it will tell if it is connected or not.
_________________________
!

download KiXnet

Top
#175973 - 2007-05-04 01:37 PM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: Lonkero]
vroedie Offline
Fresh Scripter

Registered: 2006-10-05
Posts: 30
Hi,

I've found this UDF:

 Code:
 
Dim $sRootKey
$sRootKey="HKCU\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts\"
 
Dim $asSub,$sSub, $asSpl, $sSpl
 
	$asSub=ReadRegValArr($sRootKey)
		For Each $sSub in $asSub
		$asSpl = Split($sSub, "\")[3]
			;For Each $sSpl in $asSpl
		"	Printer: "+$asSpl[3]+@CRLF
			;Next
		Next

Exit 0
   
Function ReadRegValArr($sKey)
	Dim $i,$sSubKey
 	Redim $ReadRegValArr[0]
 	$i=0
	$sSubKey=EnumValue($sKey,$i)	
	While Not @ERROR
		ReDim Preserve $ReadRegValArr[$i]
		$ReadRegValArr[$i]=$sSubKey		
		$i=$i+1
		$sSubKey=EnumValue($sKey,$i)	
	Loop
	If @ERROR=259 Exit 0 Else Exit @ERROR EndIf
EndFunction



Now the problem I'm having is with the split function.

How do I declare or use split to only show the last part of the string? so it only shows the printername and not the server name

regards

Top
#175974 - 2007-05-04 01:50 PM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: vroedie]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
you would go with something like:
 Code:
$name = "\\server\share"

$name=split($name,"\")
$name=$name[ubound($name)]

$name ?


or for the ones wanting oneliners:

 Code:
$name="\\server\share"
$name=split($name,"\")[ubound(split($name,"\"))]
$name ?

;or
$name="\\server\share"
$name=substr($name,instrrev($name,"\")+1)
$name ?

_________________________
!

download KiXnet

Top
#175975 - 2007-05-04 01:58 PM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: Lonkero]
vroedie Offline
Fresh Scripter

Registered: 2006-10-05
Posts: 30
just to make sure that I understand:

 Code:
 
$name = "\\server\share" 

$name=split($name,"\") ;splits the \\server\share into 4 parts and puts them in an array. 
$name=$name[ubound($name)] ;redefine the $name variable with the last part of the array?

$name ?



but couldn't i also use

 Code:
? $name[3]


then, since the array will always exist of 4 elements?

regards

Top
#175976 - 2007-05-04 02:05 PM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: vroedie]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
If the array is always 4 elements (0 to 3) ? $name[3] will work. Just to be safe you could do ? $name[ubound($name)] so you will always get the last part even if the array size changes to 3 or 5 or something like that.

You will always need to split $name to be able to show only the last piece.


Edited by Mart (2007-05-04 02:08 PM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#175977 - 2007-05-04 02:34 PM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: Mart]
vroedie Offline
Fresh Scripter

Registered: 2006-10-05
Posts: 30
thanks.

here's the code that I've got. It reads the registry for the printers and puts them in an array.

 Code:
Dim $sRootKey
$sRootKey="HKCU\Software\Microsoft\Windows NT\CurrentVersion\PrinterPorts\"
 
Dim $asSub,$sSub, $name, $sSpl, $j
	Redim $asPrinters[0]
	$j = 0
	
	$asSub=ReadRegValArr($sRootKey)
		For Each $sSub in $asSub
		$name=split($sSub,"\")
		$name=$name[ubound($name)]
		Redim Preserve $asPrinters[$j]
		$asPrinters[$j] = $name
		$j = $j + 1
		Next

		For Each $sPrinter in $asPrinters
		"	Printer: "+$sPrinter+@CRLF
		Next
Exit 0
   
Function ReadRegValArr($sKey)
	Dim $i,$sSubKey
 	Redim $ReadRegValArr[0]
 	$i=0
	$sSubKey=EnumValue($sKey,$i)	
	While Not @ERROR
		ReDim Preserve $ReadRegValArr[$i]
		$ReadRegValArr[$i]=$sSubKey		
		$i=$i+1
		$sSubKey=EnumValue($sKey,$i)	
	Loop
	If @ERROR=259 Exit 0 Else Exit @ERROR EndIf
EndFunction


regards,

jeroen

Top
#175980 - 2007-05-04 03:53 PM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: vroedie]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
If it helps any, I just went through a similar situation here.

I found a tool specifically for dealing with Novell printers:

http://www.novell.com/coolsolutions/tools/14416.html

It can list or delete Novell printers - I used the WshPipe() UDF to pump the output into an array so I could just loop through and re-map the Novell printers on a workstation without messing with any other printers.

Here's a snippet of what I did, just for reference:

 Code:
Dim $NovellPrinters[0]
Dim $NovellPorts[0]
Dim $NovellDrivers[0]
$x = 0
$y = 0
$w = 0

$ShellCMD = "printer.exe list " + chr(34) + "*" + chr(34) + " " + chr(34) + "\\novell\*" + chr(34)

$NovellPrinterRawList = WshPipe($ShellCMD)

for each $Printer in $NovellPrinterRawList
	if instr($Printer,"PrinterName")
		$PrinterName = split($Printer,": ")
		$NovellPrinters[$x] = $PrinterName[1]
		$x = $x + 1
		ReDim Preserve $NovellPrinters[$x]
	endif
	if instr($Printer,"PortName")
		$PortName = split($Printer,": ")
		$NovellPorts[$y] = $PortName[1]
		$y = $y + 1
		ReDim Preserve $NovellPorts[$y]
	endif
	if instr($Printer,"DriverName")
		$DriverName = split($Printer,": ")
		$NovellDrivers[$w] = $DriverName[1]
		$w = $w + 1
		ReDim Preserve $NovellDrivers[$w]
	endif
next

;--------------------------------------
; Remap other installed Novell printers
;--------------------------------------

for $z = 0 to ubound($NovellPrinters)
if $NovellPrinters[$z] <> ""
	select
	; Downstairs 8100
	case instr($NovellPorts[$z],"PrnQ8100")
		select
		case instr($NovellDrivers[$z],"PCL")
			if not PriMapState ("\\nt_print\HP8100-PCL6")
				if PriMapState($NovellPrinters[$z])
					$ShellCMD = "rundll32 printui.dll,PrintUIEntry /dl /n " + chr(34) + $NovellPrinters[$z] + chr(34)
 					Shell $ShellCMD
 				endif
				$rc = AddPrinter("\\nt_print\HP8100-PCL6","_")
				if $rc <> 1
					? "Error " @ERROR + " " + @SERROR
				endif
			endif
	 ; and so on for all the different printers / trays
	 endselect
endif


AddPrinter() came out of the UDF forum, as well.

Top
#175990 - 2007-05-04 08:51 PM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: eriqjaffe]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
tool?
you are saying that you didn't use pure kix? \:o
_________________________
!

download KiXnet

Top
#175991 - 2007-05-04 08:57 PM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: Lonkero]
Benny69 Offline
Moderator
*****

Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
EveryBody?! All together: 'Tisk Tisk, for shame' ;\)
_________________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)

Top
#175992 - 2007-05-04 08:58 PM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: Benny69]
eriqjaffe Offline
Hey THIS is FUN

Registered: 2004-06-24
Posts: 214
Loc: Arlington Heights, IL USA
But...but...but...I used WshPipe()! That has to count for something! \:\)
Top
#175999 - 2007-05-04 10:52 PM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: eriqjaffe]
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, wshpipe is neutral.
it uses wsh, which is negative. on the other hand, it's a udf, which is good.
+-0
_________________________
!

download KiXnet

Top
#176038 - 2007-05-07 02:54 PM Re: Function EnumPrinterConnections2() gives only Novell printer [Re: Lonkero]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
LOL
_________________________
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 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.079 seconds in which 0.035 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