C# Change printer driver programmatically

170 Views Asked by At

How can I automate below wizard using C# so that I can install "XPS Class Printer Driver" for my virtual printer.

enter image description here

I have created a installer by which I have created printer and port but problem is I want to use Microsoft XPS Printer Driver which is not installed on machine. I can install it from above Printer driver wizard but couldn't found a way to automate it via C#.

I know we can use DRIVER_INFO_6 or Management api but don't know how ?

Thanks !

1

There are 1 best solutions below

0
BradleyInKona On

Microsoft XPS Printer Driver is installed as part of the Windows feature "Microsoft XPS Document Writer".

Control Panel -> Programs -> Programs and Features -> Windows Features

You can enable this feature programmatically via the command line (with elevated/administrator privileges).

dism /online /Enable-Feature /FeatureName:Printing-XPSServices-Features

Using C# you can run the command using Process.Start. You may need to modify your application's app.config and use runas.exe to achieve elevated privileges necessary for the dism command.