Setting the "KeepPrintedDocuments" property in .NET.

Here is what we are trying to do:

We want an unobtrusive way to take everything that the client prints on his computer (all our clients work with POS systems and use exclusively Windows XP) and send them to us, and we decided that the best way to do this is to create an aC # application that sends us your spool files, which we can easily analyze.

However, this requires setting "Save all printed documents" to true. We want to do this in our application, and not manually, for the following reason: some (hundreds) of our customers, due to lack of a better word, are dumb. We don’t want to force them to interfere with the control panel ... our technical support specialists are as busy as possible.

Here, where I ran into a problem:

string searchQuery = "SELECT * FROM Win32_Printer"; ManagementObjectSearcher searchPrinters = new ManagementObjectSearcher(searchQuery); ManagementObjectCollection printerCollection = searchPrinters.Get(); foreach (ManagementObject printer in printerCollection) { PropertyDataCollection printerProperties = printer.Properties; foreach (PropertyData property in printerProperties) { if (property.Name == "KeepPrintedJobs") { printerProperties[property.Name].Value = true; } } } 

This should, as far as I can tell from several hours of WMI research, set the printer's KeepPrintedJobs property to true ... but it does not work. Once the foreach loop ends, KeepPrintedJobs will return to false. We would prefer to use WMI and not interfere with the registry, but I can not waste time trying to do this job. Any ideas on what's missing?

+6
source share
1 answer

Try adding a Put() call to ManagementObject to explicitly save the changes, for example:

 foreach (ManagementObject printer in printerCollection) { PropertyDataCollection printerProperties = printer.Properties; foreach (PropertyData property in printerProperties) { if (property.Name == "KeepPrintedJobs") { printerProperties[property.Name].Value = true; } } printer.Put(); } 

Hope this helps.

+3
source

Source: https://habr.com/ru/post/923666/


All Articles