Check access to files, get process ID

Is it possible to check if a file is accessible in a specific directory by process X and get the process identifier (in C ++ or better C #)?

I think that there should be a moment when a process accesses a file before it opens it. (for example, antivirus tools also use this)

Example:

  • I double click the txt file
  • Before notepad is automatically opened, a C ++ or C # program must get the process identifier in notepad before it is opened.

Is it possible? Someone told me that this can be done with low-level hooks, but I did not find a โ€œfile access hookโ€.

Thank.

+3
source share
3 answers
HWND hWnd = FindWindow(0, "Untitled - Notepad"); //Specify the title of notepad.exe
DWORD ProcessId = GetWindowThreadProcessId(hWnd, &ProcessId);
+1

, - API. : http://www.codeproject.com/KB/system/hooksys.aspx

API - . , , , : http://madshi.net/

, . , , , ; , . , API , .

# , .

+1

As far as I know, there is no direct way to control the files as you described above with C #; since these low-level tasks are always performed in kernel mode.

You will need to create a system file driver, which is not an easy task, but if you want to try it yourself, here you should start with .

0
source

Source: https://habr.com/ru/post/1733698/


All Articles