LPT1: Text LPT2: \\NCSERVER\HP LaserJet 4000 Series PCL 6 LPT3: \\NCSERVER\OKI320However, 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.
FORM PRINTER Transmittals LPT3 Reports LPT2 Receipts LPT3I 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.
*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