How to connect C ++ in explorer rename event

I can not be more clear than my title .: P

I want to run my program whenever a user renames a file in Windows Explorer (and only in Explorer). Here is a simple layout:

Rename hook hook

A simple tutorial link will be very helpful. I could not find anything.: /

Thanks in advance.

PS I'm new to C ++

+4
source share
2 answers

It seems like connecting to the Windows API might be a better choice. You will want to intercept all calls related to renaming Windows files (i.e. MoveFile, MoveFileEx, SHFileOperation, possibly more). There are several commercial open source solutions; Microsoft Detours , Madshi madCodeHook and the free, open source EasyHook .

This approach, when everything is done correctly, will allow you to capture all the renaming of files in the system.

+3
source

I would avoid binding the API as much as possible. It gets really ugly really fast.

There are two ways to understand that you can approach this. Both methods have several common factors:

  • ReadDirectoryChangesW API. For a very good implementation of this API, see this article.
  • You need to minimize your dependencies, so ... Use the Microsoft compiler, a link to the DLL runtime, stick to C as much as possible, etc. This reduces problems. Loading things into shell memory space is already quite problematic.

The first method is to use ReadDirectoryChangesW from the Explorer shell extension, which does nothing. Keep it minimal. I'm sure I saw the do nothing shell extension as an example in some Microsoft docs.

The second method is to pack your code as a DLL and use the system hook to load your DLL only in Explorer. The system hook should only load inside Explorer to prevent false notifications via ReadDirectoryChangesW .

Hope this helps and that you are not using it for something evil.

+2
source

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


All Articles