需要帮助打开锁定的打印机后台打印文件 (.SHD)

发布于 2024-12-03 14:21:31 字数 784 浏览 0 评论 0原文

我对位于 Windows 打印假脱机目录“C:\Windows\System32\spool\PRINTERS”内的影子文件 (.shd) 内的一些信息感兴趣。每次启动打印作业时,都会在该目录中创建假脱机文件 (.spl) 和影子文件 (.shd)。到目前为止,我已经成功地检测到打印作业何时开始,并且能够暂停该打印作业。如果您不暂停作业,文件最终会到达打印机,然后被 Windows 删除。

我的问题是。我无法打开 .SHD 文件,因为它们被锁定,当 sprint 后台处理程序打开它们时,您无法读取它们。我什至尝试过在 Windows 资源管理器中访问该文件并将该文件简单地复制到另一个文件,但这也不起作用。我可以打开 .SPL 假脱机文件。我只是等待,假脱机程序很快就释放了该文件。但对于影子文件,它会永久保留该文件。不幸的是,这正是我需要的。

我专门用来打开文件的代码行如下:

m_spoolJobStream = new FileStream(spoolFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

我得到的 IOException 是:

该进程无法访问文件“C:\Windows\system32\spool\PRINTERS\FP00083.SHD”,因为该文件正在被另一个进程使用。

所以是的,它正在被另一个进程使用。它被窗口的打印后台处理程序服务使用。但我认为对此我无能为力。我想做的就是读取文件。我不想对其进行任何更改。我能在这里做些什么吗?或者我只是被搞砸了?

I'm interested in some information inside a shadow file (.shd) located inside the windows print spooling directory "C:\Windows\System32\spool\PRINTERS". Every time a print job is started, a spool file (.spl) and a shadow file (.shd) are created in that directory. So far I have been successful in detecting when a print job has started, and have been able to pause that print job. If you don't pause the job, the files eventually make their way to the printer and then are deleted by windows.

My problem is. I cannot open the .SHD files because they are locked in such a way that you can not read them while they are open by the sprint spooler. I've even tried going to the file in windows explorer and simply copying the file to another file, and that didn't work either. The .SPL spool files I can open though. I simply wait, and fairly quickly the spooler release that file. For the shadow file though, it permanently holds on to this file. Unfortunately, its the one I need.

The line of code I'm using specifically to open the file is as follows:

m_spoolJobStream = new FileStream(spoolFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

The IOException I get is:

The process cannot access the file 'C:\Windows\system32\spool\PRINTERS\FP00083.SHD' because it is being used by another process.

So yes, it is being used by another process. Its being used by the window's print spooler service. But I don't think there is anything I can do about that. All I want to do is read the file. I don't want to make any changes to it. Is there anything I can do here or am I just screwed?

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

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

发布评论

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

评论(5

澜川若宁 2024-12-10 14:21:31

选中选项:“保留打印文档”(如果您有 HP 打印机),然后查看您的假脱机文件夹,影子文件和假脱机文件都在那里。

输入图片此处描述

Check the option: "Keep printed documents" (if you have HP printer) and then see your spool file folder, both shadow and spool files would be there.

enter image description here

风吹过旳痕迹 2024-12-10 14:21:31

好吧,我没有找到解决这个问题的方法。我怀疑这个问题没有解决方案,这是设计使然的。然而,我确实找到了另一种方式来获取我想要的信息(至少到目前为止看起来如此)。

我正在使用winspool.drv 库中的FindNextPrinterChangeNotification() 例程。这个家伙返回一个指向 PRINTER_NOTIFY_INFO 结构的指针,该结构又包含 PRINTER_NOTIFY_INFO_DATA 结构的数组。在该数组中,有一个元素的“Field”成员标记为“JOB_NOTIFY_FIELD_DEVMODE”。该元素包含一个相当大的 DEVMODE 类型结构。该结构由 M$ 解释,此处 http:// /msdn.microsoft.com/en-us/library/dd183565%28v=vs.85%29.aspx 。该结构看起来包含我正在寻找的内容,并且根据此页面显然包含在 .SHD 文件中 http://www.undocprint.org/formats/winspool/shd。我想知道该 .SHD 文件中还有什么内容,但我仍然无法打开它,因为它在作业暂停时被锁定,并且我怀疑它会保持锁定状态直到作业完成。哦,好吧,我认为我的新解决方案无论如何都更优雅。

Well, I did not find a way around this problem. I suspect there is no solution for this and it is by design. However I did find another way to get the information I wanted (at least it seems so thus far).

I'm using the FindNextPrinterChangeNotification() routine out of the winspool.drv library. This guy returns a pointer to a PRINTER_NOTIFY_INFO structure, which in turn contains an array of PRINTER_NOTIFY_INFO_DATA structures. Within that array, there is an element with its "Field" member marked as "JOB_NOTIFY_FIELD_DEVMODE". This element contains a fairly large structure of type DEVMODE. The structure is explained by M$ here http://msdn.microsoft.com/en-us/library/dd183565%28v=vs.85%29.aspx . This structure looks like it contains what I'm looking for and apparently is wrapped up in the .SHD file anyways according to this page http://www.undocprint.org/formats/winspool/shd. I'd like to know what else is in that .SHD file, but I still can't open it because its locked while the job is paused, and I suspect that it stays locked until the job is complete. Oh well, I think my new solution is more elegant anyways.

披肩女神 2024-12-10 14:21:31

只需确保在盒子和服务器上的假脱机中暂停作业,然后您应该能够复制/打开/移动 shd 文件,就像复制/打开/移动 spl 文件一样。无论如何,为我工作...

Just make sure you pause the job in the spool on BOTH your box and the server, then you should be able to copy/open/move the shd file just like you can the spl file. Worked for me, anyway...

吾家有女初长成 2024-12-10 14:21:31

这对我有用:
- 悬挂打印机(例如卡纸)
- 打印并观察正在创建的 .SHD 和 .SPL
- 停止打印后台处理程序
- 打开文件

This works for me:
- Hang your printer (e.g. jam the paper)
- Print and observe .SHD and .SPL being created
- Stop Print Spooler
- Open the file

一人独醉 2024-12-10 14:21:31

问题可能是 FileShare.ReadWrite 参数。您要求读取和写入文件,也许这就是您收到错误的原因。您应该尝试请求只读权限。

The problem might be the FileShare.ReadWrite parameter. You're asking to read and write on the file and maybe that's why you get an error. You should try asking for read-only permission.

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