Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 26 |
Nodes: | 6 (0 / 6) |
Uptime: | 59:32:48 |
Calls: | 633 |
Calls today: | 1 |
Files: | 1,188 |
D/L today: |
32 files (20,076K bytes) |
Messages: | 180,583 |
Not really, but as a workaround:[snip]
use a .bat instead:
or 2nd idea: a little app launcher .exe with only a listbox
with a list of apps and a start button, then ShellEx with
relative path.
Hello all,
I'm trying to create relative shortcuts* (for use on a removable USB harddisk) and can't seem to find out how it works.
* the target of the link is relative to the location of the link itself.
I'm puzzled; don't . and .. work in shortcuts?
On 2025/9/2 10:36:46, R.Wieser wrote:
Hello all,
I'm trying to create relative shortcuts* (for use on a removable USB
harddisk) and can't seem to find out how it works.
* the target of the link is relative to the location of the link itself.
[]
I'm puzzled; don't . and .. work in shortcuts?
A shortcut is designed to be copied or moved anywhere.
If the Original file is moved (somewhere), you are required to create
a new Shortcut (new absolute path).
If you want a file to appear in two places (on the same partition),
then mklink or junction.exe might work.
but when the program "works out where it is", as some programs
do, it is going to find that it is not located in the portable
folder where all the DLLs are located.
Right now, the betting money is on a shortcut with an absolute
path inside it.
But I don't know - if the "Start in" field is not filled in, does the shortcut [or, perhaps more accurately, whatever's processing it]
assume it is in some prefefined location, such as %windows%\system32
or something like that, rather than where the shortcut actually is?
If the shortcut icon uses an absolute path, then it can be copied
or moved anywhere.
Yes, but that's not "relative".
R didn't say _why_ he wanted "relative shortcuts":
all I could think of was that he wanted to be able to move/copy an entire structure - shortcuts and targets - to a different location (say, another machine, or a memory stick or external drive which might have a
different letter at times).
Paul,
A shortcut is designed to be copied or moved anywhere.
And, as it looks now, their *only* goal. I can imagine using a full path as the default, but ignoring relative paths is just a "it works for us" short-sighteness.
... unless you have a good reason why relative paths would not be possible ?
If the Original file is moved (somewhere), you are required to create
a new Shortcut (new absolute path).
Nope. It will try to find the target itself, but gives you the option to browse for it.
I could easily do without that behaviour (its search method is opaque) and just get an "target has gone" error. Have not seen any configuration for that though.
If you want a file to appear in two places (on the same partition),
then mklink or junction.exe might work.
Hard links do not work on FAT32 (thumb)drives. And neither program exists on my OS (XPsp3).
but when the program "works out where it is", as some programs
do, it is going to find that it is not located in the portable
folder where all the DLLs are located.
:-) Pros and cons. They have to be weighted.
Right now, the betting money is on a shortcut with an absolute
path inside it.
Not usable on a removable (thumb)drive I'm afraid.
... hence my (subject-line) question.
Regards,
Rudy Wieser
Hello all,
I'm trying to create relative shortcuts* (for use on a removable USB harddisk) and can't seem to find out how it works.
* the target of the link is relative to the location of the link itself.
I'm programming against the IShellLink interface ( https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ishelllinka) ,
which suggests a relative path is possible (SetRelativePath), but I'm not able to get it to work or find code explaining how to do it.
I did find this : https://devblogs.microsoft.com/oldnewthing/20171019-00/?p=97247 , but I'm not even sure if that is what I'm after ... :-|
Question: does someone have an example to what I'm supposed to do to make it happen ?
There is a feature called "AppPath" or so, where executables not
in the regular path environment variable, are stored in the Registry.
I somehow doubt a USB key would be allowed a reference in there.
Only partition letters "in good standing" like C: *should* be
stored there.
But that's just a demo that at some point, they decided to augment
%path% type environment variables, with a few more pointers.
Just leave your EXE and DLL in the bin\ subdirectory you created
and people will find it :-)
Or, consult the people who make portable applications, and maybe
they have a treatise on the subject.
...
Or, consult the people who make portable applications, and maybe
they have a treatise on the subject.
Wrong focus. Although its likely my desired relative shortcut will point to an executable or two, it would also be used to point to folders, textfiles and other. Just like the current shortcut can do.
Hello all,
I'm trying to create relative shortcuts* (for use on a removable USB harddisk) and can't seem to find out how it works.
* the target of the link is relative to the location of the link itself.
I'm programming against the IShellLink interface ( https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ishelllinka) ,
which suggests a relative path is possible (SetRelativePath), but I'm not able to get it to work or find code explaining how to do it.
I did find this : https://devblogs.microsoft.com/oldnewthing/20171019-00/?p=97247 , but I'm not even sure if that is what I'm after ... :-|
Question: does someone have an example to what I'm supposed to do to make it happen ?
On Tue, 9/2/2025 7:34 PM, J. P. Gilliver wrote:
On 2025/9/2 10:36:46, R.Wieser wrote:
Hello all,
I'm trying to create relative shortcuts* (for use on a removable USB
harddisk) and can't seem to find out how it works.
* the target of the link is relative to the location of the link itself.
[]
I'm puzzled; don't . and .. work in shortcuts?
A shortcut is designed to be copied or moved anywhere.
If the shortcut icon is sitting on the desktop, and
it says ..\programname.exe , that's not going to work.
If the shortcut icon uses an absolute path, then it can be copied
or moved anywhere. If the Original file is moved (somewhere), you
are required to create a new Shortcut (new absolute path).
If you want a file to appear in two places (on the same partition),
then mklink or junction.exe might work. Then, the item is no longer
a shortcut, it's a file, and it looks like a file icon. A hardlinkSo far, I've (AFAIK) managed to not get involved with metro "app.s";
of a file can be moved to the desktop, but when the program
"works out where it is", as some programs do, it is going to find
that it is not located in the portable folder where all the
DLLs are located.
Right now, the betting money is on a shortcut with an absolute
path inside it. Then, the executable that is loaded, is loaded
from the same folders as where the DLLs are located (right next
to the EXE).
*******
The rules are different for Metro.App , but the newsgroup
list does not hint that this is a requirement.
# A folder full of scum and villainy (mixed types are present)
explorer.exe shell:AppsFolder
# These are two shortcuts, compared.
# I might even find both of these in AppsFolder (on a newer OS).
[Picture]
https://i.postimg.cc/ZR6KdXfH/shortcut-comparison.gif
Paul
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)
Real links are not an option? https://learn.microsoft.com/en-us/windows/win32/fileio/hard-links-and-junctions
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 did find this : https://devblogs.microsoft.com/oldnewthing/20171019-00/?p=97247 , but I'm not even sure if that is what I'm after ... :-|
Hello all,
I'm trying to create relative shortcuts* (for use on a removable USB harddisk) and can't seem to find out how it works.
* the target of the link is relative to the location of the link itself.
I'm programming against the IShellLink interface ( https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ishelllinka) ,
which suggests a relative path is possible (SetRelativePath), but I'm not able to get it to work or find code explaining how to do it.
I did find this : https://devblogs.microsoft.com/oldnewthing/20171019-00/?p=97247 , but I'm not even sure if that is what I'm after ... :-|
Question: does someone have an example to what I'm supposed to do to make it happen ?
Regards,
Rudy Wieser
Real links are not an option? https://learn.microsoft.com/en-us/windows/win32/fileio/hard-links-and-junctions
Udo,
Real links are not an option?
https://learn.microsoft.com/en-us/windows/win32/fileio/hard-links-and-junctions
The first one doesn't work with FAT 32 (the default for thumbdrives), and the second has the same problem a shortcut has : using full pathnames.
On Wed, 9/3/2025 3:47 AM, R.Wieser wrote:
Paul,
A shortcut is designed to be copied or moved anywhere.
There is a feature called "AppPath" or so, where executables not
in the regular path environment variable, are stored in the Registry.
Hello all,
I'm trying to create relative shortcuts* (for use on a removable USB harddisk) and can't seem to find out how it works.
* the target of the link is relative to the location of the link itself.
I'm programming against the IShellLink interface ( https://learn.microsoft.com/en-us/windows/win32/api/shobjidl_core/nn-shobjidl_core-ishelllinka) ,
which suggests a relative path is possible (SetRelativePath), but I'm not able to get it to work or find code explaining how to do it.
I did find this : https://devblogs.microsoft.com/oldnewthing/20171019-00/?p=97247 , but I'm
not even sure if that is what I'm after ... :-|
Question: does someone have an example to what I'm supposed to do to make it happen ?
Regards,
Rudy Wieser
I haven't found any code example to add the StringData
structure.
Looks like you have to create the .lnk file by yourself.
so you have to add these 2 flags
SLDF_FORCE_NO_LINKINFO
SLDF_FORCE_NO_LINKTRACK
Shortcut file strictly use absolute path.
The *relative path part* of it (set by SetRelativePath),
Even if a relative path is used to set the (normal) Path field,
the Shell Link API will expand it to a full path.
Also, SetIDList only accept absolute IDList.
The only way to create a shortcut file with its Path field set
to a relative path, is to craft the shortcut file without using
Shell Link API.
Though, I'm not sure about the actual result when such shortcut
file is used, since the Shell Link API is expecting absolute paths
for all fields.
A solution without programming:
https://optimumx.com/download/Shortcut.zip
Z: is a USB drive
make a link to Z:\test\test2\dxcpl.exe
For Win 11:
Make a batch file that has a list of the items you want to find.
Manually select the item and have batch enter its name into "Quick Search" in task bar and followed with a CR and search result will include present location of the item
J.P. ,
But I don't know - if the "Start in" field is not filled in, does the
shortcut [or, perhaps more accurately, whatever's processing it]
assume it is in some prefefined location, such as %windows%\system32
or something like that, rather than where the shortcut actually is?
Using IShellLink to create the shortcut I get the root-of-roots, the desktop folder. And I can't edit the shortcuts target and working-directory properties anymore (the fields are grayed out). Why ? Good question.
If the shortcut icon uses an absolute path, then it can be copied
or moved anywhere.
Yes, but that's not "relative".
Indeed. Paul just tried to tell me why using an absolute path is the best idea ever and I should not want anything else.
R didn't say _why_ he wanted "relative shortcuts":
:-) You even quoted the reason in your post ! :
[quote=me, initial post]
(for use on a removable USB harddisk)
[/quote]
all I could think of was that he wanted to be able to move/copy an entire
structure - shortcuts and targets - to a different location (say, another
machine, or a memory stick or external drive which might have a
different letter at times).
Or move to another location on the same drive, or to another drive on the same 'puter. All examples where relative shortcuts would be usefull.
Regards,
Rudy Wieser
Shugo,
so you have to add these 2 flags
SLDF_FORCE_NO_LINKINFO
SLDF_FORCE_NO_LINKTRACK
I did, and saw no difference.
Thats the problem with "just do it" suggestions. Without test cases and/or description *when* those flags should have effect its rather hard to check (w|t)hat they actually do. :-(
But have you noticed this :
"Deleting those two pieces of information means that the shell cannot use them to help find the shortcut.
*If the file doesn't exist at the specified absolute path*,
then the relative path will be applied to the location of the shortcut itself, and the shell will look for the file at the resulting location"
(bolding mine)
That means that the "its now relative" trick will only work when the origional target file isn't there anymore.
Now imagine copying a folder-tree, containing a document and a shortcut to it, to somewhere else , and than double-clicking the copied shortcut to edit the also just copied document.
You won't like the result. :-|
Schugo,
A solution without programming:
https://optimumx.com/download/Shortcut.zip
Z: is a USB drive
make a link to Z:\test\test2\dxcpl.exe
That is a solution for the current computer.
The idea is to have the shortcut on an USB (thumb)drive, and have it work even when its put into another 'puter (and getting another drive letter ). ...
Schugo,
A solution without programming:
https://optimumx.com/download/Shortcut.zip
Z: is a USB drive
make a link to Z:\test\test2\dxcpl.exe
That is a solution for the current computer.
It works!
The magic happens after "File not found",
Schugo,
It works!
The magic happens after "File not found",
I already posted to you why that will not always work.
Furthermore, what you describe is what a standard shortcut already does - but only when you actually try to open the target, not when you read the shortcuts stored paths.
if you think so... works fine for me.
Another thing :
[quote=you]
The magic happens after "File not found", when you point
it to the file, the .lnk is updated with realtive paths.
[/quote]
Are you *sure* that the result is again a relative path (to the target), and not an absolute path as it normally contains ? As the shortcut-creating program doesn't seem to work for me, can you check ?
But what again is your exact problem, if it works on changed
drive letters and when moved to a different drive even deep
down in a directory?
I haven't tested it, but I'm 99% sure that it works also on a
different windows installation, if that works.
But what again is your exact problem, if it works on changed
drive letters and when moved to a different drive even deep
down in a directory?
Assuming you are talking about a standard shortcut, it doesn't work as long as the origional target is still present (read : the subtree is copied).
I haven't tested it, but I'm 99% sure that it works also on a
different windows installation, if that works.
Thats part of the problem : in /some/ (normal) situations it works, and in other (as normal) situations it won't. And thats just begging for Murphys
law to be invoked. :-(
As an example, try this :
1) Create a textfile and write "origional" in it. Close it
2) Create a shortcut to it next to that textfile.
3) copy the textfile and shortcut to some other spot on the same 'puter
4) Open the copied textfile and replace "origional" with "copy". Close it
5) Double-click the copied shortcut. I /want/ to see the textfile with "copied" in it, but that is not what happens - at least, not here.
ok, that's true, unless the original file is moved/deleted,
then the "copy" is opened...
I'm happy that it works with changed drive letters, your use
case is like never happening in my reality ;)
Hello all,
I'm trying to create relative shortcuts* (for use on a removable USB harddisk) and can't seem to find out how it works.
"R.Wieser" wrote :
Hello all,
I'm trying to create relative shortcuts* (for use on a removable USB
harddisk) and can't seem to find out how it works.
It looks like I ran head-first into some "over-engenering". :-(
As I could not find any way to create a relative shortcut using the IShellLink object, I took a better look at the Shortcut file itself. And going on a hunch, I was able to solve the problem in the most basic way ever : by manually creating a shortcut file.
It turns out that writing the header with only the "HasRelativePath" flag set and than the desired (counted-length) relative path followed by four bytes all Zero (as the end of extras list of blocks) does the trick.
Adding other strings (arguments, working directory, description) the same way also works.
One downside though : when going into the properties and changing the target causes the shortcut to revert to its normal, absolute paths format.
... At least, here on my XPsp3 machine.