Add script to IP port on Microsoft Server 2019 as Print Server

Im currently trying to setup fake printer on server to obtain files and store them on disc to use them in another app. I need to intercept print request from other computer when it choose this fake printer and use windows build in print action (ctrl + p).

Now printer is added, and is visible through network -> server computer -> printer. I can use it as printing device for example in word document. On a server i can run powershell script for only monitoring port and already created print jobs.
I have seen a possibility to add script in this window, but there should be also option for it and im thinking that should be albe to intercept request at its start.
configue tcp/ip port window

Have anybody else wanted to intercept printer jobs to acces files? Does windows server need additional roles or options to be able to do that? Or maybe i should add specific driver for fake printer. I have seen hp universal print monitor port but i didnt use it. I have created tcp/ip port.
Also i heard about custom print processor but its is also black magic for me haha.

I used console app in c# to also monitor jobs but cannot extract actual file from it. I dont think it is usefull but it showed me each print job request to printers or fake printers throught server

#include <windows.h>
#include <stdio.h>
#include <winspool.h>

#pragma comment(lib, "winspool.lib")

#define MAX_PRINTER_NAME 256
#define MAX_JOB_NAME 256

void SavePrintJobData(HANDLE hPrinter, JOB_INFO_2* pJobInfo) {
    DWORD dwNeeded = 0, dwReturned = 0;
    BYTE* pJobData = NULL;

    if (!GetJob(hPrinter, pJobInfo->JobId, 2, NULL, 0, &dwNeeded)) {
        if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
            pJobData = (BYTE*)malloc(dwNeeded);
            if (pJobData) {
                if (GetJob(hPrinter, pJobInfo->JobId, 2, pJobData, dwNeeded, &dwReturned)) {
                    JOB_INFO_2* pFullJobInfo = (JOB_INFO_2*)pJobData;

                    char filename[MAX_PATH];
                    sprintf_s(filename, sizeof(filename), "C:\PrintJobs\%s", pFullJobInfo->pDocument);

                    FILE* file;
                    if (fopen_s(&file, filename, "wb") == 0) {
                        if (pFullJobInfo->pDatatype && strcmp(pFullJobInfo->pDatatype, "RAW") == 0) {
                            // Próba pobrania surowych danych zadania
                            DWORD cbWritten;
                            if (ReadPrinter(hPrinter, file, pFullJobInfo->Size, &cbWritten)) {
                                printf("Raw data saved to: %sn", filename);
                            }
                            else {
                                printf("Error reading raw data.n");
                            }
                        }
                        else {
                            printf("Jos isn in raw format.n");
                        }
                        fclose(file);
                    }
                    else {
                        printf("Error open file to save.n");
                    }
                }
                free(pJobData);
            }
        }
    }
}

void MonitorPrintJobs() {
    PRINTER_NOTIFY_INFO* pInfo = NULL;
    PRINTER_NOTIFY_OPTIONS options;
    HANDLE hChange = NULL;
    DWORD dwChange;

    PRINTER_NOTIFY_OPTIONS_TYPE types[1];
    types[0].Type = JOB_NOTIFY_TYPE;
    types[0].Reserved0 = 0;
    types[0].Reserved1 = 0;
    types[0].Reserved2 = 0;
    types[0].Count = 1;
    types[0].pFields = (PWORD)calloc(1, sizeof(WORD));
    types[0].pFields[0] = JOB_NOTIFY_FIELD_DOCUMENT;

    options.Version = 2;
    options.Flags = 0;
    options.Count = 1;
    options.pTypes = types;

    HANDLE hPrinter = NULL;
    PRINTER_DEFAULTS defaults = { NULL, NULL, PRINTER_ACCESS_USE };

     if (OpenPrinter(NULL, &hPrinter, &defaults)) {
        hChange = FindFirstPrinterChangeNotification(hPrinter, PRINTER_CHANGE_ALL, 0, &options);

        if (hChange != INVALID_HANDLE_VALUE) {
            while (TRUE) {
                dwChange = WaitForSingleObject(hChange, INFINITE);
                if (dwChange == WAIT_OBJECT_0) {
                    DWORD dwResult;
                    if (FindNextPrinterChangeNotification(hChange, &dwResult, &options, (LPVOID*)&pInfo)) {
                        for (DWORD i = 0; i < pInfo->Count; i++) {
                            if (pInfo->aData[i].Type == JOB_NOTIFY_TYPE && pInfo->aData[i].Field == JOB_NOTIFY_FIELD_DOCUMENT) {
                                JOB_INFO_2* pJobInfo = NULL;
                                DWORD cbNeeded = 0, cReturned = 0;

                                EnumJobs(hPrinter, 0, 1, 2, NULL, 0, &cbNeeded, &cReturned);
                                if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) {
                                    pJobInfo = (JOB_INFO_2*)malloc(cbNeeded);
                                    if (EnumJobs(hPrinter, 0, 1, 2, (LPBYTE)pJobInfo, cbNeeded, &cbNeeded, &cReturned)) {
                                        SavePrintJobData(hPrinter, pJobInfo);
                                    }
                                    free(pJobInfo);
                                }
                            }
                        }
                    }
                    FindNextPrinterChangeNotification(hChange, NULL, NULL, NULL);
                }
            }
            FindClosePrinterChangeNotification(hChange);
        }
        ClosePrinter(hPrinter);
    }

    free(types[0].pFields);
}

int main() {
    MonitorPrintJobs();
    return 0;
}

Thank you in advance for your answer.

New contributor

Obalony Pivvot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật