I’ve seen some related questions but failed to find the exact solution for my problem…
Anyway, I have an invalid symlink made like this:
mklink link path/to/dir
Meaning I’m linking to a directory without the /D flag.
However, when I try to open the target file using the WinApi CreateFile it fails. Do I need to open the symlink as a file or as a directory?
CreateFile(path_to_link,
0,
0,
NULL,
OPEN_EXISTING,
[*],
NULL)
When I specify a directory at [*] the function fails (Access Denied by GetLastError(). I believe that’s because the path itself configured as a file, since I have valid permission to all relevant files).
What do I need to put at [*] to handle path/to/dir ?
Notes:
- I must handle this kind of invalid use of mklink
- My final goal is to get the absolute path of
path/to/dir. If there is another way withoutCreateFileI’d love to hear about it:)
As explained in the comment, it behaves like a Shell Link. Here is one way to resolve the target path, it uses the IShellItem2 COM interface and the System.Link.TargetParsingPath property.
C++ version:
C version: