2

Using this answer, I can create shortcuts (.lnk files) for various executables and folders.

When I use the Recent Items directory (C:\Users\%USERNAME%\AppData\Roaming\Microsoft\Windows\Recent) in the SHORTCUT, the PWS call creates the shortcut, but it disappears from File Explorer quickly - too quickly to register in an Open/Save dialog.

Strangely, the file still exists; I see it in the output of dir, and creating a new shortcut manually using these steps adds (2) to the file name used in the Shortcut tab of its Properties window. Similarly, creating the shortcut on the Desktop first, then copying it to the Recent Items folder, will prompt you for an overwrite. The copies disappear too, so this isn't a workaround either way.

How do I prevent the programmatic shortcuts from disappearing from the Recent Items folder?

1 Answers1

1

The simple answer is you can use notepad to open a .lnk file, and it will get added to quick access automatically:

C:\> notepad "%userprofile%\Desktop\Microsoft Edge.lnk"

However, you can't really add a shortcut .lnk file itself to quick access or recent items. The reason is that file explorer will parse the .lnk and only add the actual target to the "Recent Items" list. The example above adds this to the recent items:

"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"

And does not include any additional info like arguments or initial directory


%AppData%\Microsoft\Windows\Recent is a virtual folder that does not really exist. As soon as Explorer recalculates the contents, files like the icon you created stop showing up. Explorer stores the actual "Recent Items" information in files named <id>.automaticDestinations-ms within hidden folders: \Recent\CustomDestinations and \Recent\AutomaticDestinations.

These are used and updated by each application's jumplist (where you can right-click notepad's icon and see a list of recent files for example).

Take a look through the answer here for a more detailed explanation of how the Recent Items directory works: https://superuser.com/a/1670209/673426.

And here is detailed MS documentation for jump lists: https://learn.microsoft.com/en-us/dotnet/api/system.windows.shell.jumplist

Cpt.Whale
  • 10,914