This example shows how to monitor creation, deletion, renaming or copying of folders.
The CopyHook handler is an ActiveX library like all other Shell Extensions. The first step is to create a new ActiveX Library. Create it with the following sequence of operations: open the Repository dialog using File | New | Other... menu, then select the ActiveX tab and click the ActiveX Library icon.
Save the created project.
You can save your project now.
Take a look on the properties of the CopyHook component. First of all you will see that the new GUID was created and assigned to the component's CLSID property. It is this GUID will be used by system to identify your CopyHook handler. Other properties are described in the table below:
Table 1. TSxCopyHook properties
Set components properties now as shown below:
Fig. 3. TSxCopyHook properties sample
Now the example is almost ready, it can be compiled and installed into system but it does nothing. The next step is to add some operations to be done when hook is activated. These operations should be placed into OnCopyHook event handler. This event will be fired every time the shell performs an operation with hooked objects. Processing the event you receive a chance to monitor the file operation or even enable or prohibit it. Let's implement this functionality in our example.
Create the form that will ask user about permission to perform an operation with hooked objects:
Buttons "Yes", "No" and "Cancel" should have a usual ModalResult property value - mrYes, mrNo and mrCancel respectively.
Now implement OnCopyHook event as follows:
Save the project and compile it - it is ready now! As well as any other ActiveX library the Shell+ project requires registration. You can register it in several ways:
To know more about shell extension installation please follow the link.
The final step is to test how the example works.
Create a new folder on your desktop or in any directory. You can use New | Folder items from the context menu. The newly created folder will have name "---------" or "New Folder" (it depends on the OS version). Try to rename it and you will see the confirmation window shown by our example. It will look like this one:
Press "Yes" to confirm folder renaming. If you will choose "Cancel" or "No" then renaming operation will be canceled.
The deletion operation works in the similar way. Select the test folder and delete it. Windows will show the confirmation dialog and - if the operation was confirmed - our sample confirmation window will be shown:
The folder will be deleted if the "Yes" button was pressed only.
Don't forget to uninstall the example when all tests are finished. Note that it is an example only and it will show its confirmation window until you will not unregister it. As well as installation the uninstallation can be done in many ways:
The detailed information about extension uninstallation is available here.
Use links below to download source codes of this example as well as binary files: