R
R
Roman Sopov2013-06-13 11:36:42
C++ / C#
Roman Sopov, 2013-06-13 11:36:42

How to determine the application ID in which the file is opened?

There is some application written in C++ that opens files in an associated application. The problem is that not all applications return a reference (identifier) ​​to the process.
How can you 100% find out the link?
And how can I find out if this file is open?

Searching through the titles of open windows comes to mind, but what's the best way to do this?

Thank you!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
E
Eddy_Em, 2013-06-13
@Eddy_Em

OS what?
On Linux and Linux-like: fuser, lsof | grep filename. Both (both fuser and lsof) work by scanning the tree in /proc/PIDs. Similarly, it is implemented.

A
AxisPod, 2013-06-13
@AxisPod

Hmm, why should the application return, if it needs to be received programmatically, then the CreateProcess function takes the PROCESS_INFORMATION pointer as the last parameter, where it will place the pid, handle of the process, etc.

K
Kwent, 2013-06-13
@Kwent

If I understand correctly, then to check if the file is open, you can call CreateFile with FILE_SHARE_MODE=0 and if the file is open somewhere, then the function should end with ERROR_SHARING_VIOLATION.

R
Roman Sopov, 2013-06-15
@sopov

I need to know in advance whether the file is open or not. the file is on the server and in order not to download it again, a check is needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question