winapi - ShellExecute opens shortcut instead of folder when they have the same name - Stack Overflow

admin2025-04-10  0

I found out that ShellExecute(..., L"open", ...) will choose to launch a shortcut instead of folder when the path is clearly a folder, when the folder and the shortcut has the same name besides .lnk extension for the shortcut.

To repro:

  1. Create a test.lnk in desktop, link it to any exe
  2. Create a test folder in desktop
  3. Use this code:
ShellExecute(NULL, L"open", path_w.data(), nullptr, nullptr, SW_SHOW);

where path_w is C:\Users\<UserName>\Desktop\test

ShellExecute will correctly opens the folder if test.lnk is changed to any other file extension, like text.txt. This behavior is so unexpected and seems to not documented anywhere?

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744257285a238377.html

最新回复(0)