NO

Author Topic: Enumerating remote printers  (Read 4767 times)

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Enumerating remote printers
« on: June 02, 2024, 09:05:52 PM »
Coomand-line tool to list shared printers :

Code: [Select]
#include <windows.h>

#include <winspool.h>

#include <stdio.h>

int main(int argc, char * argv[]) {

    DWORD cbBuf = 0;
    DWORD pcReturned;
    PRINTER_INFO_2 * prinfo;
    BOOL r;
    int rv = 0;
    DWORD i;

    char * err = "The EnumPrinters API could not retrieve printer information.\n";

    if (argc != 2) {
        printf("ListPrinters V1.0 by Vortex\n\nUsage : ListPrinters \\\\server\n");
        return 1;
    }

    EnumPrinters(PRINTER_ENUM_SHARED | PRINTER_ENUM_NAME, argv[1], 2, NULL, 0, & cbBuf, & pcReturned);

    if (!cbBuf) {
        printf("%s", err);
        return 2;
    }

    prinfo = (PRINTER_INFO_2 * )VirtualAlloc(0, cbBuf, MEM_COMMIT, PAGE_READWRITE);

    if (!prinfo) {
        printf("Memory allocation failed.\n");
        return 3;
    }

    r = EnumPrinters(PRINTER_ENUM_SHARED | PRINTER_ENUM_NAME, argv[1], 2, (LPBYTE) prinfo, cbBuf, & cbBuf, & pcReturned);

    if (!r) {
        printf("%s", err);
        rv = 2;

    } else {

        for (i = 0; i < pcReturned; ++i) {
            printf("%s\n", prinfo[i].pShareName);
        }
    }

    VirtualFree(prinfo, 0, MEM_RELEASE);
    return rv;

}
Code it... That's all...

Offline John Z

  • Member
  • *
  • Posts: 860
Re: Enumerating remote printers > into LOCAL Printers
« Reply #1 on: June 03, 2024, 01:37:27 PM »
Command-line tool to list shared printers :

Very neat Vortex!  Thanks!!

Hopefully you won't mind I created a derivative TOTALLY based on your program, to just list Local Printers.   
Attached project zip here. 

John Z

Offline Vortex

  • Member
  • *
  • Posts: 865
    • http://www.vortex.masmcode.com
Re: Enumerating remote printers
« Reply #2 on: June 03, 2024, 08:17:39 PM »
Hi John,

You are welcome. Thanks for your version.
Code it... That's all...