#175962 - 2007-05-04 10:22 AM
Function EnumPrinterConnections2() gives only Novell printer
|
vroedie
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
|
|
|
|
#175965 - 2007-05-04 11:40 AM
Re: Function EnumPrinterConnections2() gives only Novell printer
[Re: Lonkero]
|
vroedie
Fresh Scripter
Registered: 2006-10-05
Posts: 30
|
Hi,
sorry, still only displays the novell printer. bugger...
|
|
Top
|
|
|
|
#175973 - 2007-05-04 01:37 PM
Re: Function EnumPrinterConnections2() gives only Novell printer
[Re: Lonkero]
|
vroedie
Fresh Scripter
Registered: 2006-10-05
Posts: 30
|
Hi,
I've found this UDF:
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
|
|
|
|
#175975 - 2007-05-04 01:58 PM
Re: Function EnumPrinterConnections2() gives only Novell printer
[Re: Lonkero]
|
vroedie
Fresh Scripter
Registered: 2006-10-05
Posts: 30
|
just to make sure that I understand:
$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
then, since the array will always exist of 4 elements?
regards
|
|
Top
|
|
|
|
#175977 - 2007-05-04 02:34 PM
Re: Function EnumPrinterConnections2() gives only Novell printer
[Re: Mart]
|
vroedie
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.
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
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:
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
|
|
|
|
#175991 - 2007-05-04 08:57 PM
Re: Function EnumPrinterConnections2() gives only Novell printer
[Re: Lonkero]
|
Benny69
Moderator
   
Registered: 2003-10-29
Posts: 1036
Loc: Lincoln, Ne
|
EveryBody?! All together: 'Tisk Tisk, for shame'
|
|
Top
|
|
|
|
#175992 - 2007-05-04 08:58 PM
Re: Function EnumPrinterConnections2() gives only Novell printer
[Re: Benny69]
|
eriqjaffe
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|