设置打印机的" KeepPrintedDocuments"在.NET物业打印机、物业、KeepPrintedDocuments、QUOT

2023-09-05 00:20:19 作者:舍得舍不得都要舍得、

下面就是我们正在努力做的事情:

Here's what we're trying to do:

我们要采取一切客户打印自己的电脑上(我们所有的客户都在运行POS系统,并使用Windows XP只),并将其发送给我们一个不显眼的方式,我们已经决定这样做是最好的方法创建一个C#应用程序,将我们自己的假脱机文件,我们已经可以很容易地分析。

We want an unobtrusive way of taking everything a client prints on their computer (all of our clients are running POS systems and use Windows XP exclusively) and sending it to us, and we've decided the best way to do that is to create a c# app that sends us their spool files, which we can already parse easily.

然而,这需要设置保留所有已打印的文档为真。我们要做到这一点在我们的应用程序,而不是手动,由于以下原因:我们的客户一些(数百个)是,由于缺乏一个更好的词,哑巴。我们不希望迫使他们浪费时间在控制面板......我们的技术支持人很忙碌,因为它是。

However, this requires setting "Keep All Printed Documents" to true. We want to do this in our app rather than manually, for the following reason: some (hundreds) of our clients are, for lack of a better word, dumb. We don't want to force them to mess around in control panel... our tech support people are busy enough as it is.

在此处,我碰到的一个问题:

Here's where I've run 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;
        }
    }
}

这应该,据我可以告诉从几个小时WMI研究,每个打印机的KeepPrintedJobs属性设置为true ...但它不工作。一旦foreach循环结束后,KeepPrintedJobs被设置为false。我们想preFER注册表中的周围使用WMI,而不是一塌糊涂,但我不能花永远努力使这项工作。在缺少了什么任何想法?

This should, as far as I can tell from several hours of WMI research, set the KeepPrintedJobs property of each printer to true... but its not working. As soon as the foreach loop ends, KeepPrintedJobs is set back to false. We'd prefer to use WMI and not mess around in the registry, but I can't spend forever trying to make this work. Any ideas on what's missing?

推荐答案

尝试添加调用将()的ManagementObject 明确地坚持了变化,像这样的:

Try adding a call to Put() on the ManagementObject to explicitly persist the change, like this:

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 that helps.