Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting All Available Printers and their local port
Message
From
12/12/2002 11:51:31
 
 
To
12/12/2002 10:09:41
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00732227
Message ID:
00732297
Views:
33
This message has been marked as a message which has helped to the initial question of the thread.
>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
>
>

How about using Wscript.Network - the EnumPrinterConnections() method should return a collection you can use:
oWSHNet = CREATEOBJ('Wscript.Network')
oPrinterColl = oWSHNet.EnumPrinterConnections()
FOR i = 0 TO oPrinterColl.Count-1 STEP 2
  ? oPrinterColl.Item(i),oPrinterColl.Item(i+1)  && Port (UNC if no port is associated),Windows device name
ENDFOR
>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
>
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform