by dbSoft » Tue Mar 21, 2006 10:21 am
[code]
//---------------------------
Function AGetPrinters()
//---------------------------
Local aPrinters, cText, cToken := Chr(15)
// Passing no second param or passing ZERO to GetProfStr()
// grabs entire section in .ini file. Each printer is separated by a
// null char (Chr(0)) and a CRLF. We just strip them out
cText := StrTran( StrTran( StrTran( ;
GetProfStr( "Devices", 0 ), Chr(0), cToken ), Chr(13) ), Chr(10) )
aPrinters := Array( Len( cText ) - Len( StrTran( cText, cToken ) ) )
AEval( aPrinters, {|cPrn,nEle| ;
aPrinters[nEle] := StrToken( cText, nEle, cToken ) } )
Return aPrinters
/*
1 Open tdosprn.prg and change the way ::cPort is assigned in method ::New()
from
::cPort := cPort+iif(!"."$cPort,".PRN","")
to
::cPort := cPort + If( ! "." $ cPort .and. ! "\\" $ cPort, ".PRN", "" ) // considers the port can be a network route
(\\computername\sharename)
2 use this function to get the path to the network printer. IE you'll
say wfPrnShName( "PRINTER1" ) and it will return \\computername\sharename.
Note: make sure you use Patrick Mast's
TReg32 mods if you're not using FW 2.3:
*/
///#include "FiveWin.ch"
//#define HKEY_LOCAL_MACHINE 2147483650
//---------------------
function mainPrn( cLPT )
//---------------------
#define HKEY_LOCAL_MACHINE 2147483650
//// msginfo( wfPrnShName("Epson FX-80+") )
//
return wfPrnShName( cLPT )
//--------------------------------
Function wfPrnShName( cModel )
//--------------------------------
Local oReg, nPos, cComputer, cPrinter, cShare := "", cKeyName
Default cModel := StrToken( GetProfStr( "Windows", "Device", "" ), 1, "," ) // get default printer if not provided
If IsWinNT() // for W2K,NT4,XP
IF cNET // PARAMETRE FOR Network printer
cKeyName := "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Providers\LanMan Print Services\Servers\"
If Left( cModel, 2 ) == "\\"
nPos := RAt( "\", cModel )
cComputer := SubStr( cModel, 3, nPos - 3 )
cPrinter := SubStr( cModel, nPos + 1 )
oReg := TReg32():New( HKEY_LOCAL_MACHINE, ;
cKeyName + cComputer + "\Printers\" + cPrinter )
If oReg:nError == 0 // in case the printer name doesn't exist
cShare := "\\" + cComputer + "\" + ; // create in the form of "\\computername\sharename"
StrTran( oReg:Get( "Share Name", "" ), Chr(0) )
Endif
oReg:close()
Endif
ELSE
cKeyName := "SOFTWARE\Microsoft\Windows NT\CurrentVersion\Print\Printers\"
oReg := TReg32():New( HKEY_LOCAL_MACHINE, cKeyName + cModel )
If oReg:nError == 0 // in case the printer name doesn't exist
cPrinter := StrTran( oReg:Get( "Port", "" ), Chr(0) )
/// If Left( cPrinter, 2 ) == "\\" // if it's not a network printer it returns "LPT1:" or "LPT2:" or whatever applies
cShare := cPrinter // this one is already in the form "\\computername\sharename"
/// Endif
Endif
oReg:close()
ENDIF
Else // for Win9x
cKeyName := "System\CurrentControlSet\Control\Print\Printers\"
oReg := TReg32():New( HKEY_LOCAL_MACHINE, cKeyName + cModel )
If oReg:nError == 0 // in case the printer name doesn't exist
cPrinter := StrTran( oReg:Get( "Port", "" ), Chr(0) )
/// If Left( cPrinter, 2 ) == "\\" // if it's not a network printer it returns "LPT1:" or "LPT2:" or whatever applies
cShare := cPrinter // this one is already in the form "\\computername\sharename"
/// Endif
Endif
oReg:close()
Endif
Return cShare
[/quote]