ShellNotify Component
Properties Methods Events Config Settings Errors
The ShellNotify component enables monitoring file system change notifications.
Syntax
TcbxShellNotify
Remarks
The ShellNotify component provides a simple way to monitor changes such as creation, renaming, deletion, or modification of files or folders. The component uses the Windows API to register as an observer of shell notifications.
Activate
First, set the Path property to the desired location to listen for changes. The target may be a local or remote filesystem, and a path may be specified using the drive letter format or a UNC path. For instance, you can set C:\Path\To\Folder if the target is a mapped drive, or \\servername\sharename if the target is a network share.
After that, you may set the Recursive property depending on whether you would like to include changes for subfolders. You may also set the value of Notifications to control the types of changes to monitor.
ShellNotify component = new ShellNotify();
component.Path = "C:\Temp";
component.Recursive = True;
The next step is to call Activate to begin listening for changes. As users interact with files and folders at the specified Path, the corresponding events will be triggered. Activate must be called again if the Explorer process is terminated.
component.Activate();
Deactivate
To unregister as an observer of changes, call the Deactivate method. This action will cease monitoring change notifications and only needs to be called once.
component.Deactivate();
PIDLs
A PIDL (or an IDL) is a fundamental Windows Shell concept. At a high level, it is pretty simple, as it is just a value that represents a Windows Shell item in the Windows Shell Namespace. It is a bit like a full filesystem path for a physical file or folder, except that it is a binary object and not a string. The name "PIDL" and "IDL" can be used interchangeably. The leading P stands for pointer, the IDL stands for item identifier list, and PIDL generally refers to an IDL itself rather than the pointer to it.
The below information is provided as a general knowledge. Your application will deal with PIDLs only when they denote some Windows Shell items that are not necessarily a part of the Windows Shell namespace extension that you create. Such PIDLs can be used with the Windows Shell API if you decide to call it directly. When CBFS Shell exposes these PIDL values they will appear hex-encoded. If an application needs to call a shell function, it has to decode the PIDL before calling that function.
Just like a full filesystem path is a list of strings separated by the directory separator (on Windows, it is the \ (backslash) character), a PIDL is a list (L is for list) of Ids (identifiers). Unlike a filesystem path, though, a PIDL is binary, and Ids are separated by a special PIDL separator (two consecutive zero bytes).
Microsoft provides more details about PIDLs here Identifying Namespace Objects.
Troubleshooting
Following are some helpful resources for troubleshooting issues.
- If events are not triggered for any changes, note that the component relies on Explorer running and not terminating or restarting. If the Explorer process ends then you will need to call Activate again.
- If certain events are not triggered, it may be that the system components behave differently depending on the target you are monitoring. For instance, to monitor changes to a network share one needs to handle ItemChanged.
- If you are seeing strange behavior not contained in this list, please reach out to us with a description of the problem and we are happy to help. Our support team is available over email at support@callback.com
Property List
The following is the full list of the properties of the component with short descriptions. Click on the links for further details.
Notifications | The property specifies which changes to monitor. |
Path | The property specifies what path or namespace item to monitor. |
Recursive | This property specifies whether changes in subfolders should be monitored. |
Method List
The following is the full list of the methods of the component with short descriptions. Click on the links for further details.
Activate | This method initiates monitoring for changes. |
Config | Sets or retrieves a configuration setting. |
Deactivate | This method stops monitoring changes. |
Event List
The following is the full list of the events fired by the component with short descriptions. Click on the links for further details.
Error | This event is fired if an unhandled error occurs during an event. |
FileCreated | This event fires when a file is created. |
FileDeleted | This event fires when a file is deleted. |
FileRenamed | This event fires when a file is renamed. |
FolderCreated | This event fires when a folder is created. |
FolderDeleted | This event fires when a folder is deleted. |
FolderRenamed | This event fires when a folder is renamed. |
ItemChanged | This event fires when any item is changed. |
Config Settings
The following is a list of config settings for the component with short descriptions. Click on the links for further details.
BuildInfo | Information about the product's build. |
LicenseInfo | Information about the current license. |
Notifications Property (ShellNotify Component)
The property specifies which changes to monitor.
Syntax
property Notifications: Integer read get_Notifications write set_Notifications;
Default Value
0x0002001F
Remarks
The property specifies which changes the component should monitor. The value may be a combination of the following flags:
UPDATE_TYPE_CREATE | 0x00000001 | A new item or folder is created.
This flag must be exclusive if used. |
UPDATE_TYPE_CHANGE | 0x00000002 | An item or folder has been changed.
For folders, use this flag to tell the Windows Shell that the folder's contents have been changed. |
UPDATE_TYPE_DELETE | 0x00000004 | An item or folder has been deleted. |
UPDATE_TYPE_ATTRIBUTES | 0x00000008 | The attributes of an item or a folder have been updated. |
UPDATE_TYPE_RENAME | 0x00000010 | An item was renamed; its name and possibly its Id have been changed.
This flag must be exclusive if used. |
The default value of 0x0002001F (CHANGE_NOTIFY_DEFAULT) is a combination of the following flags:
- CHANGE_NOTIFY_CREATE
- CHANGE_NOTIFY_CREATE_FOLDER
- CHANGE_NOTIFY_DELETE
- CHANGE_NOTIFY_DELETE_FOLDER
- CHANGE_NOTIFY_RENAME
- CHANGE_NOTIFY_RENAME_FOLDER
Path Property (ShellNotify Component)
The property specifies what path or namespace item to monitor.
Syntax
property Path: String read get_Path write set_Path;
Default Value
''
Remarks
This property specifies the target to monitor. If omitted, all of the Windows Shell namespace is monitored. A target may be any namespace item such as a folder or non-folder item.
An application may set this property to a filesystem path in drive-letter format, a path in UNC format, or a hex-encoded PIDL if a Windows Shell folder or item with no filesystem path is to be monitored. For instance:
- C:\Path\To\Folder
- \\<server>\<share>
Recursive Property (ShellNotify Component)
This property specifies whether changes in subfolders should be monitored.
Syntax
property Recursive: Boolean read get_Recursive write set_Recursive;
Default Value
true
Remarks
This property specifies whether changes in subfolders of the folder specified by Path property should also be monitored. This setting will be ignored if the Path property references a non-folder item.
Activate Method (ShellNotify Component)
This method initiates monitoring for changes.
Syntax
procedure Activate();
Remarks
Use this method to begin monitoring for changes in the target location specified by the Path property. The types of changes that will be included in monitoring are set in the Notifications property.
Activate must be called again if the Explorer process is terminated.
Config Method (ShellNotify Component)
Sets or retrieves a configuration setting.
Syntax
function Config(ConfigurationString: String): String;
Remarks
Config is a generic method available in every component. It is used to set and retrieve configuration settings for the component.
These settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.
To set a configuration setting named PROPERTY, you must call Config("PROPERTY=VALUE"), where VALUE is the value of the setting expressed as a string. For boolean values, use the strings "True", "False", "0", "1", "Yes", or "No" (case does not matter).
To read (query) the value of a configuration setting, you must call Config("PROPERTY"). The value will be returned as a string.
Deactivate Method (ShellNotify Component)
This method stops monitoring changes.
Syntax
procedure Deactivate();
Remarks
Use this method to stop monitoring for changes and unregister as an observer of change notifications.
Error Event (ShellNotify Component)
This event is fired if an unhandled error occurs during an event.
Syntax
type TErrorEvent = procedure ( Sender: TObject; ErrorCode: Integer; const Description: String ) of Object;
property OnError: TErrorEvent read FOnError write FOnError;
Remarks
This event fires if an unhandled error occurs. Developers can use this information to track down unhandled errors that occur in the component.
ErrorCode contains an error code and Description contains a textual description of the error.
FileCreated Event (ShellNotify Component)
This event fires when a file is created.
Syntax
type TFileCreatedEvent = procedure ( Sender: TObject; const PIDL: TBytes; const Path: String ) of Object;
property OnFileCreated: TFileCreatedEvent read FOnFileCreated write FOnFileCreated;
Remarks
This event fires upon creation, when the Windows Shell registers file creation within the namespace.
PIDL contains a byte array that represents an item in the Windows Shell namespace. Please see PIDL for more information.
Path contains the full path of the item. This parameter is only applicable when the item is part of a filesystem with a path.
Note: The events are triggered in the same thread that the Windows Shell used for a notification. Performing time-consuming operations within this event will prevent other events firing in a timely manner and may affect overall performance.
FileDeleted Event (ShellNotify Component)
This event fires when a file is deleted.
Syntax
type TFileDeletedEvent = procedure ( Sender: TObject; const PIDL: TBytes; const Path: String ) of Object;
property OnFileDeleted: TFileDeletedEvent read FOnFileDeleted write FOnFileDeleted;
Remarks
This event fires upon deletion, when the Windows Shell has registered file deletion.
PIDL contains a byte array that represents an item in the Windows Shell namespace. Please see PIDL for more information.
Path contains the full path of the item. This parameter is only applicable when the item is part of a filesystem with a path.
Note: The events are triggered in the same thread that the Windows Shell used for a notification. Performing time-consuming operations within this event will prevent other events firing in a timely manner and may affect overall performance.
FileRenamed Event (ShellNotify Component)
This event fires when a file is renamed.
Syntax
type TFileRenamedEvent = procedure ( Sender: TObject; const PIDL: TBytes; const Path: String; const NewPIDL: TBytes; const NewPath: String ) of Object;
property OnFileRenamed: TFileRenamedEvent read FOnFileRenamed write FOnFileRenamed;
Remarks
This event fires upon renaming, when the Windows Shell has registered file renaming in one or more Windows Shell items.
PIDL contains a byte array that represents an previous item in the Windows Shell namespace. Please see PIDL for more information.
Path contains the full previous path of the item. This parameter is only applicable when the item is part of a filesystem with a path.
NewPIDL contains the new PIDL.
NewPath contains the new path. This parameter is only applicable when the item is part of a filesystem with a path.
Note: The events are triggered in the same thread that the Windows Shell used for a notification. Performing time-consuming operations within this event will prevent other events firing in a timely manner and may affect overall performance.
FolderCreated Event (ShellNotify Component)
This event fires when a folder is created.
Syntax
type TFolderCreatedEvent = procedure ( Sender: TObject; const PIDL: TBytes; const Path: String ) of Object;
property OnFolderCreated: TFolderCreatedEvent read FOnFolderCreated write FOnFolderCreated;
Remarks
This event fires upon folder creation, when the Windows Shell has registered a folder is created.
PIDL contains a byte array that represents an item in the Windows Shell namespace. Please see PIDL for more information.
Path contains the full path of the item. This parameter is only applicable when the item is part of a filesystem with a path.
Note: The events are triggered in the same thread that the Windows Shell used for a notification. Performing time-consuming operations within this event will prevent other events firing in a timely manner and may affect overall performance.
FolderDeleted Event (ShellNotify Component)
This event fires when a folder is deleted.
Syntax
type TFolderDeletedEvent = procedure ( Sender: TObject; const PIDL: TBytes; const Path: String ) of Object;
property OnFolderDeleted: TFolderDeletedEvent read FOnFolderDeleted write FOnFolderDeleted;
Remarks
This event fires upon folder deletion, when the Windows Shell has registered a folder has been deleted.
PIDL contains a byte array that represents an item in the Windows Shell namespace. Please see PIDL for more information.
Path contains the full path of the item. This parameter is only applicable when the item is part of a filesystem with a path.
Note: The events are triggered in the same thread that the Windows Shell used for a notification. Performing time-consuming operations within this event will prevent other events firing in a timely manner and may affect overall performance.
FolderRenamed Event (ShellNotify Component)
This event fires when a folder is renamed.
Syntax
type TFolderRenamedEvent = procedure ( Sender: TObject; const PIDL: TBytes; const Path: String; const NewPIDL: TBytes; const NewPath: String ) of Object;
property OnFolderRenamed: TFolderRenamedEvent read FOnFolderRenamed write FOnFolderRenamed;
Remarks
This event fires upon folder renaming, when the Windows Shell has registered renaming in one or more Windows Shell items.
PIDL contains a byte array that represents an previous item in the Windows Shell namespace. Please see PIDL for more information.
Path contains the full previous path of the item. This parameter is only applicable when the item is part of a filesystem with a path.
NewPIDL contains a new PIDL.
NewPath contains a new path. This parameter is only applicable when the item is part of a filesystem with a path.
Note: The events are triggered in the same thread that the Windows Shell used for a notification. Performing time-consuming operations within this event will prevent other events firing in a timely manner and may affect overall performance.
ItemChanged Event (ShellNotify Component)
This event fires when any item is changed.
Syntax
type TItemChangedEvent = procedure ( Sender: TObject; const PIDL: TBytes; const Path: String; const NewPIDL: TBytes; const NewPath: String; Changes: Integer ) of Object;
property OnItemChanged: TItemChangedEvent read FOnItemChanged write FOnItemChanged;
Remarks
This event fires upon any change, when the Windows Shell has registered a creation, deletion, renaming, or updates in one or more Windows Shell items. The types of updates can include changes to size, attributes, security settings, last write, and last access time.
PIDL contains a byte array that represents an item in the Windows Shell namespace. If the set of changes includes renaming, this parameter contains the previous PIDL. Please see PIDL for more information.
Path contains the full path of the item. This parameter is only applicable when the item is part of a filesystem with a path. If the set of changes includes renaming, this parameter contains the previous Path.
NewPIDL contains a new PIDL. This parameter is only used when the set of changes includes renaming.
NewPath contains a new path. This parameter is only used when the set of changes includes renaming.
Changes specifies the type of change. The value can be one of the following:
CHANGE_NOTIFY_RENAME | 0x00000001 | The name of a nonfolder item has changed.
Both PIDL/Path and NewPIDL/NewPath parameters are valid. Renaming of a folder is indicated by the CHANGE_NOTIFY_RENAME_FOLDER flag. |
CHANGE_NOTIFY_CREATE | 0x00000002 | A nonfolder item has been created.
Either PIDL, Path, or both parameters are valid. Creation of a folder is indicated by the CHANGE_NOTIFY_CREATE_FOLDER flag. |
CHANGE_NOTIFY_DELETE | 0x00000004 | A nonfolder item has been deleted.
Either PIDL, Path, or both parameters are valid. Deletion of a folder is indicated by the CHANGE_NOTIFY_DELETE_FOLDER flag. |
CHANGE_NOTIFY_CREATE_FOLDER | 0x00000008 | A folder has been created.
Either PIDL, Path, or both parameters are valid. |
CHANGE_NOTIFY_DELETE_FOLDER | 0x00000010 | A folder has been removed.
Either PIDL, Path, or both parameters are valid. |
CHANGE_NOTIFY_ATTRIBUTES | 0x00000800 | The attributes of an item or folder have changed
Either PIDL, Path, or both parameters are valid. |
CHANGE_NOTIFY_UPDATE_FOLDER | 0x00001000 | The contents of an existing folder have changed, but the folder still exists and has not been renamed.
Either PIDL, Path, or both parameters are valid. |
CHANGE_NOTIFY_UPDATE | 0x00002000 | An existing item (a folder or a non-folder item) has changed, but the item still exists and has not been renamed.
Either PIDL, Path, or both parameters are valid. |
CHANGE_NOTIFY_RENAME_FOLDER | 0x00020000 | The name of a folder has changed.
Both PIDL/Path and NewPIDL/NewPath parameters are valid. |
CHANGE_NOTIFY_DEFAULT | 0x0002001F | The default value of the Notifications property |
Note: The events are triggered in the same thread that the Windows Shell used for a notification. Performing time-consuming operations within this event will prevent other events firing in a timely manner and may affect overall performance.
Config Settings (ShellNotify Component)
The component accepts one or more of the following configuration settings. Configuration settings are similar in functionality to properties, but they are rarely used. In order to avoid "polluting" the property namespace of the component, access to these internal properties is provided through the Config method.Base Config Settings
- Product: The product the license is for.
- Product Key: The key the license was generated from.
- License Source: Where the license was found (e.g., RuntimeLicense, License File).
- License Type: The type of license installed (e.g., Royalty Free, Single Server).
Trappable Errors (ShellNotify Component)
ShellNotify Errors
2 | An item with given ID cannot be found. The CBFSSHELL_ERR_FILE_NOT_FOUND constant is provided for convenience and may be used in place of the numeric value. |
20 | Cannot load native proxy DLL. The CBFSSHELL_ERR_CANT_LOAD_PROXY constant is provided for convenience and may be used in place of the numeric value. |
28 | The major version of the proxy DLL doesn't match the major version of the .NET assembly. The CBFSSHELL_ERR_PROXY_VERSION_MISMATCH constant is provided for convenience and may be used in place of the numeric value. |
38 | End of data stream has been reached and no data could be read. The CBFSSHELL_ERR_STREAM_EOF constant is provided for convenience and may be used in place of the numeric value. |
55 | Proxy DLL not installed properly. The CBFSSHELL_ERR_NOT_INSTALLED constant is provided for convenience and may be used in place of the numeric value. |
56 | Installation of the native proxy DLL failed. The CBFSSHELL_ERR_INSTALL_FAILED constant is provided for convenience and may be used in place of the numeric value. |
57 | Uninstallation of the native proxy DLL failed. The CBFSSHELL_ERR_UNINSTALL_FAILED constant is provided for convenience and may be used in place of the numeric value. |
58 | Initialization of the native proxy DLL failed. The CBFSSHELL_ERR_INIT_FAILED constant is provided for convenience and may be used in place of the numeric value. |
59 | The current license and the ID in the native proxy DLL name don't match. The CBFSSHELL_ERR_PROXY_NAME_MISMATCH constant is provided for convenience and may be used in place of the numeric value. |
60 | Writing to the Windows registry failed. The CBFSSHELL_ERR_CANT_WRITE_TO_REGISTRY constant is provided for convenience and may be used in place of the numeric value. |
61 | This Menu instance has already been started. The CBFSSHELL_ERR_ALREADY_STARTED constant is provided for convenience and may be used in place of the numeric value. |
62 | A menu item with the same verb is already registered. The CBFSSHELL_ERR_MENU_ITEM_ALREADY_REG constant is provided for convenience and may be used in place of the numeric value. |
63 | No menu items have been registered. The CBFSSHELL_ERR_MENU_ITEM_NOT_REG constant is provided for convenience and may be used in place of the numeric value. |
87 | The passed parameter was not valid. The CBFSSHELL_ERR_INVALID_PARAMETER constant is provided for convenience and may be used in place of the numeric value. |
122 | The provided buffer is too small to accommodate all the data that must be placed in it. The CBFSSHELL_ERR_INSUFFICIENT_BUFFER constant is provided for convenience and may be used in place of the numeric value. |