Reputation: 51
I'm currently creating a WPF application, and like to add as a small side feature the ability to clear the windows file explorer history.
If one were to manually do this operation, it is possible via the file menu within a file explorer window, as shown here.
My goal is pretty much to programmatically execute the same action as this button does, but I've been unable to find what executable or user32.dll method is behind this operation (if it exists), and been also unsuccessful on finding the full logic behind it (namely, finding what folder and files it targets), to replicate it.
Can you help me?
Upvotes: 2
Views: 462
Reputation: 1
I also tried to find programmatic way to do this. Using Spy++ to find "Clear" button id I finally made it.
This AutoHotkey script do the work (tested on Win11):
#Requires AutoHotkey v1.1
#NoEnv
#NoTrayIcon
#SingleInstance ignore
SetBatchLines, -1
WM_COMMAND := 0x111
; Reversed in Spy++
IDD_FOLDER_OPTIONS_CLEARHISTORY := 30086
end_time := A_TickCount + 3000
DllCall("Shell32.dll\Options_RunDLL" (A_IsUnicode?"W":"A"), "Ptr",A_ScriptHwnd, "Ptr",0, "Str","0", "UInt",0)
while (A_TickCount < end_time && !(hOpts := WinExist("ahk_class #32770 ahk_exe explorer.exe")))
Sleep 0
if (hOpts) {
WinHide
hTab := DllCall("FindWindowEx", "Ptr",hOpts, "Ptr",0, "Ptr",32770, "Ptr",0, "Ptr")
DetectHiddenWindows, On
SendMessage, WM_COMMAND, IDD_FOLDER_OPTIONS_CLEARHISTORY,,, ahk_id %hTab%
WinClose ahk_id %hOpts%
}
Upvotes: -1
Reputation: 51
As the comment by dxiv suggested, you can achieve this via the following:
enum ShellAddToRecentDocsFlags
{
Pidl = 0x001,
Path = 0x002,
PathW = 0x003
}
[DllImport("shell32.dll", CharSet = CharSet.Unicode)]
private static extern void SHAddToRecentDocs(ShellAddToRecentDocsFlags flag, string path);
// How To Clear Everything
SHAddToRecentDocs(ShellAddToRecentDocsFlags.Pidl, null);
Upvotes: 3