Intermittent error saving properties in shortcut link #8179

Open
opened 2026-01-31 01:22:43 +00:00 by claunia · 2 comments
Owner

Originally created by @j4james on GitHub (May 16, 2020).

Environment

Windows build number: Version 10.0.18362.719
Windows Terminal version (if applicable): Commit b46d393061

Steps to reproduce

  1. Checkout and build a recent version of the OpenConsole solution (I'm using an x64 release build in case that makes a difference).
  2. Create a shortcut to the OpenConsole.exe that has just been built (in the bin\x64\Release directory).
  3. Start the app from the shortcut.
  4. Open the properties dialog.
  5. Press Enter to save and close the dialog.
  6. Repeat steps 4 and 5 a few dozen times.

Expected behavior

You should be able to open and close the dialog without any problems.

Actual behavior

After a couple of repeats, it'll eventually fail when closing the dialog with the error:

Unable to modify the shortcut:
C:\...\OpenConsole.exe - Shortcut.lnk.
Check to make sure it has not been deleted or renamed.

I added a bunch of OutputDebugString logging in the code, and I tracked down the problem to the s_GetLoadedShellLinkForShortcut method when called from s_SetLinkValues. It tries to load the shortcut with mode STGM_READWRITE | STGM_SHARE_EXCLUSIVE and the IPersistFile::Load fails with error 0x80070020, which is the HRESULT equivalent of ERROR_SHARING_VIOLATION.

This is not always easy to reproduce - sometimes I can repeat the process hundreds of times without an error, but other times it'll fail on the first or second attempt. I don't whether maybe it's just something wrong with my system.

Originally created by @j4james on GitHub (May 16, 2020). # Environment Windows build number: Version 10.0.18362.719 Windows Terminal version (if applicable): Commit b46d39306124363a4104afb74fa9b6657b1d17d0 # Steps to reproduce 1. Checkout and build a recent version of the _OpenConsole_ solution (I'm using an x64 release build in case that makes a difference). 2. Create a shortcut to the `OpenConsole.exe` that has just been built (in the `bin\x64\Release` directory). 3. Start the app from the shortcut. 4. Open the properties dialog. 5. Press <kbd>Enter</kbd> to save and close the dialog. 6. Repeat steps 4 and 5 a few dozen times. # Expected behavior You should be able to open and close the dialog without any problems. # Actual behavior After a couple of repeats, it'll eventually fail when closing the dialog with the error: Unable to modify the shortcut: C:\...\OpenConsole.exe - Shortcut.lnk. Check to make sure it has not been deleted or renamed. I added a bunch of `OutputDebugString` logging in the code, and I tracked down the problem to the `s_GetLoadedShellLinkForShortcut` method when called from `s_SetLinkValues`. It tries to load the shortcut with mode `STGM_READWRITE | STGM_SHARE_EXCLUSIVE` and the `IPersistFile::Load` fails with error `0x80070020`, which is the `HRESULT` equivalent of `ERROR_SHARING_VIOLATION`. This is not always easy to reproduce - sometimes I can repeat the process hundreds of times without an error, but other times it'll fail on the first or second attempt. I don't whether maybe it's just something wrong with my system.
claunia added the Product-ConhostArea-SettingsIssue-BugPriority-3 labels 2026-01-31 01:22:43 +00:00
Author
Owner

@j4james commented on GitHub (May 16, 2020):

I thought at first this was a recent problem, but I've just now tested with a shortcut to the cmd.exe in my Windows\System32 directory, and managed to reproduce the same error. So if it's a regression, it's at least been around for a while.

@j4james commented on GitHub (May 16, 2020): I thought at first this was a recent problem, but I've just now tested with a shortcut to the `cmd.exe` in my `Windows\System32` directory, and managed to reproduce the same error. So if it's a regression, it's at least been around for a while.
Author
Owner

@DHowett commented on GitHub (May 19, 2020):

Not terribly surprised this is fragile. Thanks for digging!

@DHowett commented on GitHub (May 19, 2020): Not terribly surprised this is fragile. Thanks for digging!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#8179