另一个进程文件句柄上的 SetFilePointer() 失败
我正在为第三方不可触摸的控制台可执行文件制作 GUI。该可执行文件读取输入文件,处理数据并生成输出文件。由于该过程可能需要很长时间,因此我需要监控进度。
我想要做的是找到控制台可执行进程ID(完成),使用进程ID检索该进程打开的文件列表(完成),然后,一旦识别出输入文件并且检索它的句柄(完成) ,我想调用 SetFilePointer(handle, 0, currentPosition) 所以它告诉我已经读取了多少文件。然后,(read/totalSize) 将为我提供该过程的进度。
问题是调用 SetFilePointer() 总是返回 0xFFFFFFFF(失败),而 GetLastError() 返回 6(无效句柄)。有什么想法吗?
先感谢您。
I'm making a GUI for a third party untouchable console executable. This executable reads an input file, processes the data and generates an output file. As the process can take a long time I need to monitor the progress.
What I want to do is to locate the console executable process id (done), with the process id retrieve the list of files opened by the process (done) and then, once the input file is identified and it's handle is retreived (done), I want to call SetFilePointer(handle, 0, currentPosition) so it tells me what ammount of file has been already read. Then, (read/totalSize) will give me the progress of the process.
THE PROBLEM is that invoking SetFilePointer() always returns 0xFFFFFFFF (fail) and GetLastError() returns 6 (invalid handle). Any ideas?
Thank you in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
句柄属于拥有进程,只能由拥有进程操作。如果您想修改另一个进程中的句柄,则需要将代码注入该进程,或使用
DuplicateHandle
。Handles belong to the owning process and can only be operated on by the owning process. If you want to modify a handle in another process you'll need to inject code into that process, or use
DuplicateHandle
.