Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Getting All Available Printers and their local port
Message
De
12/12/2002 10:09:41
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Getting All Available Printers and their local port
Divers
Thread ID:
00732227
Message ID:
00732227
Vues:
95
I am using the code at the bottom (checkports) to determine what printers are attached. I have tried aprinters() but it does tell me if what local port a network printer is mapped to. What I am trying to get is something like the following which shows all local ports and the printer NAME for each that can be used in VFP7:
LPT1:  Text
LPT2:  \\NCSERVER\HP LaserJet 4000 Series PCL 6
LPT3:  \\NCSERVER\OKI320
However, checkports returns the following:
VALIDPORT   Priv   A  checkports
        (   1)     C  "Text"
        (   2)     C  "Lexmark Z23-Z33"
        (   3)     C  "\\NCSERVER\HP LaserJet 4000 Series PCL 6"
        (   4)     C  "\\NCSERVER\OKI320"
        (   5)     C  "LPT2\\NCSERVER\HP_4000"
        (   6)     C  "LPT3\\Ncserver\OKI320"
        (   7)     C  "JUNK"
Aprinters() returns the following:
GAPRINTERS  Priv   A  checkports
   (   1,   1)     C  "Text"
   (   1,   2)     C  "LPT1:"
   (   2,   1)     C  "Lexmark Z23-Z33"
   (   2,   2)     C  "USB001"
   (   3,   1)     C  "\\NCSERVER\HP LaserJet 4000 Series PCL 6"
   (   3,   2)     C  "HPJD1"
   (   4,   1)     C  "\\NCSERVER\OKI320"
   (   4,   2)     C  "HPJD2"
The problem is that neither returns what I need. For instance aprinters() does not tell me the local port mapped to gaprinters(3,1) even though I know from checkport that LPT2 is mapped to that printer because checkport tells me that. However, checkport returns the unc name for it and I need the installed printer name for use in VFP.

Any ideas? I'm trying to take a table that has printer selections in FPD26 and convert it for use with our VFP7 app. The fpd26 table has records like the following:
FORM           PRINTER
Transmittals    LPT3
Reports         LPT2
Receipts        LPT3
I need to be able to step through the table and change every record that has LPT2 in it to the printer name that LPT2 is mapped to \\NCSERVER\HP LaserJet 4000 Series PCL 6 (that would be returned using getprinter(). In some cases the UNC name is the same as the printer name (like in the OKIDATA 320) but that is not always the case.

TIA!
Tracy
*checkports.prg
*I cannot remember who provided this on the UT (maybe Ed?)
CLEAR
LOCAL lcDeviceList, lnBufLen, lcUncBuffer,;
	lnLength, i, iv, lcLocalDevice,;
	lnResult, lcPrinter, lcTargetDevice
FOR i = 1 TO APRINTERS(gaprinters)
	gaprinters[i,1]=SPACE(1) +;
		gaprinters[i,1]
	DIMENSION validport(i)
	validport(i)=gaprinters[i,1]
ENDFOR
DECLARE SHORT QueryDosDevice IN KERNEL32.DLL ;
	STRING @ lpDeviceName, ;
	STRING @ lpTargetPath, ;
	INTEGER ucchmax
* pass null device name to get a list of DOS Devices
lcDeviceList = REPL(CHR(0),2048)
lnResult = QueryDosDevice(0,@lcDeviceList,2047)
* result is in lcDeviceList; you have to parse it - null char separators
* Get info on one device assignment
lcTargetDevice = REPL(CHR(0), 262)
lnBufLen = 261
DECLARE INTEGER WNetGetConnection IN WIN32API ;
	STRING @ lpLocalName, ;
	STRING @ lpRemoteName, ;
	INTEGER @ lplnLength
lcUncBuffer = REPL(CHR(0),261)
lnLength = LEN(lcUncBuffer)
* i=1
iv=ALEN(gaprinters,1)
FOR i = 1 TO 20
	lcLocalDevice="LPT"+ALLTRIM(STR(i))
	lnResult = QueryDosDevice(lcLocalDevice,@lcTargetDevice, lnBufLen)  && note - no :
	IF !lnResult = 0
		cTargetName = LEFT(lcTargetDevice, lnResult-2)
		IF WNetGetConnection(lcLocalDevice, @lcUncBuffer, @lnLength) = 0
			lcPrinter=lcLocalDevice+LEFT(lcUncBuffer,AT(CHR(0),lcUncBuffer)-1)
			iv=iv+1
			DIMENSION validport(iv)
			validport(iv)=lcPrinter
		ENDIF
	ENDIF
	lcLocalDevice="COM"+ALLTRIM(STR(i))
	lnResult = QueryDosDevice(lcLocalDevice,@lcTargetDevice, lnBufLen)  && note - no :
	IF !lnResult = 0
		cTargetName = LEFT(lcTargetDevice, lnResult-2)
		IF WNetGetConnection(lcLocalDevice, @lcUncBuffer, @lnLength) = 0
			lcPrinter=lcLocalDevice+LEFT(lcUncBuffer,AT(CHR(0),lcUncBuffer)-1)
			iv=iv+1
			DIMENSION validport(iv)
			validport(iv)=lcPrinter
		ENDIF
	ENDIF
ENDFOR
*!*	FOR i = 1 TO ALEN(validport,1)
*!*		validport(i)=LTRIM(validport(i))
*!*		? validport(i)
*!*	ENDFOR
* Add the junk printer
iv=iv+1
DIMENSION validport(iv)
validport(iv)="JUNK"
DISPLAY MEMORY LIKE validport
IF APRINTERS(gaprinters) > 0  && If there are installed printer drivers
	DISPLAY MEMORY LIKE gaprinters && Display the printers and ports
ELSE  && Otherwise, no printer are installed
	WAIT WINDOW 'No printers installed.' NOWAIT
ENDIF
.·*´¨)
.·`TCH
(..·*

010000110101001101101000011000010111001001110000010011110111001001000010011101010111001101110100
"When the debate is lost, slander becomes the tool of the loser." - Socrates
Vita contingit, Vive cum eo. (Life Happens, Live With it.)
"Life is not measured by the number of breaths we take, but by the moments that take our breath away." -- author unknown
"De omnibus dubitandum"
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform