Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: network printer available
I am generating a list of printers on the fly and using Con2Prt.exe install the printers with great ease, but no error is return when the server is not even there.
Is there a way to check to see if the server is even there or if the printer is available on that server and return something to use for error handling?
Here is another way to check if a server is available.....
AddExtender("WWWNT34I.DLL") ErrorMode(@OFF) wntServerInfo( "\\Myserver", 1) ErrorMode(@CANCEL) If LastError()==524 Message("Check Server","Server Does not exist") Else Message("Check Server","Server Does exist") Endif exit
wntShareInfo("\\Server", "Printername", 2, -1)
As a side comment on that line of code: I had to use the Share-type of 2 for device instead of 1 for printer. When I tried to use 1, it always failed with an error message "Unable to Access specified printer". Am I doing something wrong? This comes back and tells me @true if the printer is on that server or not.
Now that I know if the printer is on that server or not, lets get more specific. On the NT Print Server, if you bring up the printer folder, it has a column for "Status". When I take a printer offline, it shows in that column that it IS offline. is there a way to retrieve that information?
;typedef struct _PRINTER_INFO_2 { // pri2 ; ;0 LPTSTR pServerName; ;4 LPTSTR pPrinterName; ;8 LPTSTR pShareName; ;12 LPTSTR pPortName; ;16 LPTSTR pDriverName; ;20 LPTSTR pComment; ;24 LPTSTR pLocation; ;28 LPDEVMODE pDevMode; ;32 LPTSTR pSepFile; ;36 LPTSTR pPrintProcessor; ;40 LPTSTR pDatatype; ;44 LPTSTR pParameters; ;48 PSECURITY_DESCRIPTOR pSecurityDescriptor; ;52 DWORD Attributes; ;56 DWORD Priority; ;60 DWORD DefaultPriority; ;64 DWORD StartTime; ; ;68 DWORD UntilTime; ;72 DWORD Status; ;76 DWORD cJobs; ;80 DWORD AveragePPM; ; total length = 294 ??? ;} PRINTER_INFO_2; ;BOOL OpenPrinter( ; ; LPTSTR pPrinterName, // address of printer or server name ; LPHANDLE phPrinter, // address of printer or server handle ; LPPRINTER_DEFAULTS pDefault // address of printer defaults structure ; ); ;BOOL ClosePrinter( ; ; HANDLE hPrinter // handle of printer object ; ); ;BOOL GetPrinter( ; ; HANDLE hPrinter, // handle to printer of interest ; DWORD Level, // version of printer info data structure ; LPBYTE pPrinter, // pointer to array of bytes that receives printer info. structure ; DWORD cbBuf, // size, in bytes, of array of bytes ; LPDWORD pcbNeeded // pointer to variable with count of bytes retrieved (or required) ; ); ;#define PRINTER_STATUS_PAUSED 0x00000001 ;#define PRINTER_STATUS_ERROR 0x00000002 ;#define PRINTER_STATUS_PENDING_DELETION 0x00000004 ;#define PRINTER_STATUS_PAPER_JAM 0x00000008 ;#define PRINTER_STATUS_PAPER_OUT 0x00000010 ;#define PRINTER_STATUS_MANUAL_FEED 0x00000020 ;#define PRINTER_STATUS_PAPER_PROBLEM 0x00000040 ;#define PRINTER_STATUS_OFFLINE 0x00000080 ;#define PRINTER_STATUS_IO_ACTIVE 0x00000100 ;#define PRINTER_STATUS_BUSY 0x00000200 ;#define PRINTER_STATUS_PRINTING 0x00000400 ;#define PRINTER_STATUS_OUTPUT_BIN_FULL 0x00000800 ;#define PRINTER_STATUS_NOT_AVAILABLE 0x00001000 ;#define PRINTER_STATUS_WAITING 0x00002000 ;#define PRINTER_STATUS_PROCESSING 0x00004000 ;#define PRINTER_STATUS_INITIALIZING 0x00008000 ;#define PRINTER_STATUS_WARMING_UP 0x00010000 ;#define PRINTER_STATUS_TONER_LOW 0x00020000 ;#define PRINTER_STATUS_NO_TONER 0x00040000 ;#define PRINTER_STATUS_PAGE_PUNT 0x00080000 ;#define PRINTER_STATUS_USER_INTERVENTION 0x00100000 ;#define PRINTER_STATUS_OUT_OF_MEMORY 0x00200000 ;#define PRINTER_STATUS_DOOR_OPEN 0x00400000 ;#define PRINTER_STATUS_SERVER_UNKNOWN 0x00800000 ;#define PRINTER_STATUS_POWER_SAVE 0x01000000 statusoffset=72 printer_status_offline = 128 ; 0x80 status= -1 dllname=StrCat(DirWindows(1),"winspool.drv") dllhandle=DllLoad(dllname) printername="\\TESTTECH\LASER5" ;printername="\\NAN\HP 660" bbhPrinter=BinaryAlloc(4) BinaryPoke4(bbhPrinter,0,0) bbPrinter2=BinaryAlloc(10000) ; alloc way too much BinaryEODSet(bbPrinter2,10000) bbP2Size=BinaryAlloc(4) BinaryPoke4(bbP2Size,0,0) rslt1=DllCall(dllhandle,LONG:"OpenPrinterA",lpstr:printername,lpbinary:bbhPrinter,lpnull) if rslt1 == 1 hPrinter=BinaryPeek4(bbhPrinter,0) rslt2=DllCall(dllhandle,long:"GetPrinterA",long:hPrinter,long:2,lpbinary:bbPrinter2,long:10000,lpbinary:bbP2Size) if rslt2 == 1 p2Size=BinaryPeek4(bbP2size,0) status=BinaryPeek4(bbPrinter2,statusoffset) endif rslt3=DllCall(dllhandle,LONG:"ClosePrinter",long:hPrinter) endif BinaryFree(bbhPrinter) BinaryFree(bbP2Size) BinaryFree(bbPrinter2) DllFree(dllhandle) Message("status",status) if status == -1 Message(printername,"Can't locate printer") else if status & printer_status_offline Message(printername,"offline") else Message(printername,"online") endif endif
Article ID: W14483
Filename: Check if network printer available.txt
File Created: 2002:02:18:13:00:24
Last Updated: 2002:02:18:13:00:24