Re: How to create a relative shortcut ?
Schugo <[email protected]> Wed, 3 Sep 2025 21:32:25 +0200
| Newsgroups | comp.os.ms-windows.programmer.win32,alt.comp.os.windows-xp,alt.windows7.general |
|---|---|
| Organization | A noiseless patient Spider |
| Message-ID | <[email protected]> |
On 03.09.2025 19:19, R.Wieser wrote:
> Schugo,
>
>> If the file is a known filetype with a registered
>> standard app, then ShellExecute(...) or "start" in a
>> .bat should open the file just fine, even folders.
>> (just tried with start foldername)
>
> Thanks for the suggestion.
>
> I'm still hoping someone knows how to create a relative shortcut though.
I haven't found any code example to add the StringData structure.
Looks like you have to create the .lnk file by yourself.
IShellLinkA::SetRelativePath doesn't seem to do this:
https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nf-shobjidl_core-ishelllinka-setrelativepath
This is from the LNK file format:
2.1.1 LinkFlags
The LinkFlags structure defines bits that specify which shell link structures
are present in the file format after the ShellLinkHeader structure.
HasRelativePath (0x00000008)
The shell link is saved with a relative path string. If this bit is set, a
RELATIVE_PATH StringData structure (section 2.4) MUST be present
2.4 StringData
RELATIVE_PATH: An optional structure that specifies the location of the link
target relative to the file that contains the shell link. When specified, this
string SHOULD be used when resolving the link.
...
Example:
Because HasRelativePath is set, the RELATIVE_PATH StringData structure
follows:
CountCharacters: (2 bytes), 0x0007 Unicode characters.
String (14 bytes), the Unicode string: ".\a.txt".
ciao...