Skip to content

This project implements a Virtual Printer Driver for Windows using a robust architecture to intercept and manage print jobs without a physical printer. The system is built around two core components: a Port Monitor (VirtualPrinterPortMonitor.dll) and a Windows Service (VirtualPrinterService.exe)

Notifications You must be signed in to change notification settings

m0nkeyDev/virtual-printer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Virtual Printer Driver for Windows

This project implements a virtual printer in Windows using a robust architecture based on a Port Monitor and a Windows Service.

Architecture

  • Port Monitor (VirtualPrinterPortMonitor.dll): A DLL loaded by the Windows Spooler that intercepts print data and sends it to the control service via Named Pipes.
  • Windows Service (VirtualPrinterService.exe): A background service that receives the print data, saves it to C:\Temp\PrintJobs, and monitors the health of the printing subsystem.
  • Installer (VirtualPrinter.inf): An installation script to register the port monitor with the system.

Prerequisites

  • Visual Studio 2019 or later (with the "Desktop development with C++" workload).
  • CMake 15 or later.

Build Steps

Open a Developer Command Prompt for Visual Studio. Create a build directory: sh mkdir build cd build Run CMake to generate the Visual Studio project files: sh cmake .. Compile the project: sh cmake --build . --config Release The binaries (VirtualPrinterPortMonitor.dll and VirtualPrinterService.exe) will be located in build\Release.

Installation Steps (Run as Administrator)

Install the Service: Navigate to the build directory (build\Release) in an administrator terminal and run: sh VirtualPrinterService.exe install

Start the Service: sh sc start VirtualPrinterService

Install the Port Monitor: Copy VirtualPrinterPortMonitor.dll to C:\Windows\System32. Then, navigate to the source code's Installer directory, right-click on VirtualPrinter.inf and select "Install".

Create the Virtual Printer: Run the following command in an administrator terminal to create the printer. It will use the standard Microsoft XPS driver and associate it with our port. sh powershell -Command "Add-Printer -Name 'Virtual Printer' -DriverName 'Microsoft XPS Class Driver v4' -PortName 'VIRTUAL_PORT:'" Note: If the VIRTUAL_PORT: does not appear in the list of existing ports, restart the Print Spooler service (spoolsv) to load our new monitor: net stop spooler && net start spooler.

How to Test

Open any application (Notepad, Word, etc.) and print a document. Select the printer named "Virtual Printer". After printing, look for a new file in the C:\Temp\PrintJobs\ directory. The file will contain the raw print data. Check the Windows Event Viewer (under Windows Logs -> Application) for logs generated by the service.

Uninstallation (Run as Administrator)

Delete the Printer: sh powershell -Command "Remove-Printer -Name 'Virtual Printer'" Stop and Delete the Service: sh sc stop VirtualPrinterService sc delete VirtualPrinterService Uninstall the Port Monitor: * Restart the Spooler service: net stop spooler && net start spooler. * Delete the file C:\Windows\System32\VirtualPrinterPortMonitor.dll. * Delete the registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Print\Monitors\Virtual Printer Port.

About

This project implements a Virtual Printer Driver for Windows using a robust architecture to intercept and manage print jobs without a physical printer. The system is built around two core components: a Port Monitor (VirtualPrinterPortMonitor.dll) and a Windows Service (VirtualPrinterService.exe)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published