如何编写Windows 10脚本以每次打印作业打印时逐一增加计数器?

发布于 2025-02-07 05:49:40 字数 114 浏览 2 评论 0原文

我想在每次打印作业完成时,为Windows 10编写一个脚本以在.txt中添加1个。理想情况下,每天都有一个单独的计数,因此我可以看到一天内完成了多少个印刷作业。

感谢您了解如何进行此操作的任何帮助!

I'd like to write a script for Windows 10 to add 1 to a count in a .txt each time a print job completes. Ideally a separate count for each day, so I can see how many print jobs were completed in a day.

Any help in understanding how to go about this is appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你不是我要的菜∠ 2025-02-14 05:49:40

打印服务已经在每次打印时都登录 - 您只需要启用适当的事件日志频道并消耗结果日志事件:

# Enable the Microsoft-Windows-PrintService/Operational log channel
wevtutil.exe set-log Microsoft-Windows-PrintService/Operational /enabled:true

现在,启用了日志频道,打印服务将在每次执行一个事件ID 307的情况下记录事件ID 307本地打印工作。由于日志事件都有时间戳,因此每天获得计数就像使用group-object cmdlet:

# Fetch the print job events from the event log
$printJobEvents = Get-WinEvent -FilterHashtable @{ LogName='Microsoft-Windows-PrintService/Operational'; EventId=307 } 

# Group by date logged, to get a count-per-day
$printJobEvents |Group-Object { '{0:yyyy-MM-dd}' -f  $_.TimeCreated.Date } -NoElement |Sort-Object Name

The print service already logs every time it prints - you just need to enable the appropriate event log channel and consume the resulting log events:

# Enable the Microsoft-Windows-PrintService/Operational log channel
wevtutil.exe set-log Microsoft-Windows-PrintService/Operational /enabled:true

Now that the log channel is enabled, the print service will log an event with event ID 307 everytime it executes a local print job. Since the log events all have timestamps, getting a count per day is as simple as using the Group-Object cmdlet:

# Fetch the print job events from the event log
$printJobEvents = Get-WinEvent -FilterHashtable @{ LogName='Microsoft-Windows-PrintService/Operational'; EventId=307 } 

# Group by date logged, to get a count-per-day
$printJobEvents |Group-Object { '{0:yyyy-MM-dd}' -f  $_.TimeCreated.Date } -NoElement |Sort-Object Name
獨角戲 2025-02-14 05:49:40

可能有用的一种技术是查询类似的剥离器服务的统计信息:

Get-CimInstance 'Win32_PerfFormattedData_Spooler_PrintQueue' |
    Format-Table -Property Name,Jobs,TotalJobsPrinted,TotalPagesPrinted -AutoSize

这给出了这样的输出:

Name                          Jobs TotalJobsPrinted TotalPagesPrinted
----                          ---- ---------------- -----------------
Printer1                         0               50               212
Printer2                         3               13               118
Printer3                         1               33               306
_Total                           4               96               636

每次打印spooler服务重新启动时,统计数在您的最终脚本中考虑到这一点,这可能使此选项比Mathias的事件日志解决方案更棘手。

One technique that might be useful is to query stats for the spooler service like this:

Get-CimInstance 'Win32_PerfFormattedData_Spooler_PrintQueue' |
    Format-Table -Property Name,Jobs,TotalJobsPrinted,TotalPagesPrinted -AutoSize

This gives output like this:

Name                          Jobs TotalJobsPrinted TotalPagesPrinted
----                          ---- ---------------- -----------------
Printer1                         0               50               212
Printer2                         3               13               118
Printer3                         1               33               306
_Total                           4               96               636

The stats are reset each time the Print Spooler service restarts, so you'll need to take that into account in your final script, which might make this a trickier option than Mathias' event log solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文