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