Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Notifies the system that an item has been accessed, for the purposes of tracking those items used most recently and most frequently. This function can also be used to clear all usage data.
void SHAddToRecentDocs(
UINT uFlags,
[in, optional] LPCVOID pv
);
uFlags
Type: UINT
A value from the SHARD enumeration that indicates the form of the information pointed to by the pv parameter.
[in, optional] pv
Type: LPCVOID
A pointer to data that identifies the item that has been accessed. The item can be specified in this parameter in one of the following forms:
Set this parameter to NULL to clear all usage data on all items.
None
The usage statistics gathered through calls to this method are used to determine lists of items accessed most recently and most frequently. These lists are seen in the Start menu and, in Windows 7 and later, in an application's Jump List.
When this method is called, it affects the following areas:
In some cases, notably when a user opens an item through Windows Explorer or uses the common file dialog to open, save, or create a file, the Shell calls SHAddToRecentDocs on behalf of the application. An application that has a custom UI for selecting items should call SHAddToRecentDocs explicitly to ensure accurate statistics. Duplicate calls are accounted for by the system so there is no risk of skewing the data by doing so.
Executable (.exe) files are filtered from the recently used documents list in Windows XP and later versions. Although SHAddToRecentDocs will accept the path of an executable file, that file will not appear in the Recent Items list.
Folders are also accepted by SHAddToRecentDocs, but appear only in the Jump List for the Windows Explorer taskbar button. Folders do not appear in any other application's Jump List.
In certain cases, SHAddToRecentDocs attempts to register an application to handle a file type that it is not registered to handle. This occurs under these circumstances:
A set of requirements must be met for the registration to be accomplished successfully:
HKEY_LOCAL_MACHINE Software Microsoft Windows CurrentVersion Explorer FileAssociation KillList
If SHAddToRecentDocs is attempting the registration as the result of a drag-and-drop onto the taskbar button, the shell subkey is created if it does not already exist, as long as the existing application registration does not contain a NoOpenWith value and the application's executable is not listed in the KillList value.
SHAddToRecentDocs tracks document usage statistics through the verbs that are invoked to access those documents. Verbs supplied by registered IContextMenu handlers are tracked, those items appear in My Recent Documents (Windows XP) and Recent Items (Windows Vista). In Windows 7, the parent folders of the documents appear in the Jump List for the Windows Explorer taskbar button. However, the documents accessed through those IContextMenu verbs do not appear in application Jump Lists. For those items to appear in an application's Jump List, an application must call SHAddToRecentDocs explicitly.
Prior to Windows 7, only the open
verb resulted in a call to SHAddToRecentDocs. In Windows 7 and later, other verbs can also generate usage statistics. This information is used to make a Jump List's destinations more complete and accurate.
However, some classes of file type association registrations or individual IContextMenu implementations are not appropriate for this sort of tracking. The point of usage tracking is to generate a list of items that the user is likely to want to access again. If a particular verb—delete
, for instance—is inherently invoked on an item that the user will not access again, or is a secondary action such as a virus scan on a file, that verb is not appropriate for tracking. File type classes should remove themselves from this tracking through the registry entry NoRecentDocs. NoRecentDocs is of type REG_SZ and has no associated data. Its presence is all that is required to prevent the call to SHAddToRecentDocs.
For example, context menu extensions and static verbs registered under HKEY_CLASSES_ROOT in classes such as "*", "AllFileSystemObjects", or "Folder" should not be tracked. In cases such as these, the NoRecentDocs entry is added to the root of the class key as shown here to suppress tracking of documents launched through any verb or extension registered to that class:
HKEY_CLASSES_ROOT AllFileSystemObjects NoRecentDocs
The NoRecentDocs entry is assigned by default to the *, AllFileSystemObjects, Folder, Directory, and DesktopBackground class subkeys.
Individual IContextMenu implementations can opt out of tracking by adding a NoRecentDocs subkey to its Component Object Model (COM) object's registration, in its shellex subkey, as shown here:
HKEY_CLASSES_ROOT CLSID {093C7AAB-5E72-454f-A91D-CA1BC991FCEC} shellex NoRecentDocs
This subkey is not present by default on any IContextMenu implementation.
Requirement | Value |
---|---|
Minimum supported client | Windows XP [desktop apps only] |
Minimum supported server | Windows 2000 Server [desktop apps only] |
Target Platform | Windows |
Header | shlobj_core.h (include Shlobj.h) |
Library | Shell32.lib |
DLL | Shell32.dll (version 4.0 or later) |
API set | ext-ms-win-shell-shell32-l1-2-2 (introduced in Windows 10, version 10.0.14393) |
Events
May 19, 6 PM - May 23, 12 AM
Calling all developers, creators, and AI innovators to join us in Seattle @Microsoft Build May 19-22.
Register today