Shell execution of existing shortcuts works, but execution of new shortcuts fails. Why?

44 Views Asked by At

When executing a Windows shortcut in Java (and possibly .NET and other platforms), execution of an existing shortcut works without issue, but new shortcuts fail to execute regardless of settings, permissions, working directory, contents of the shortcut target, location of the shortcut, location of the target, or any shortcut-related setting.

For reference, the code in question follows, though the problem's scope is likely wider and stranger than this specific code implies:

// Replace <SomeWindowsShortcut.lnk> with an actual shortcut name.
// Shortcuts are implemented as a file with the hidden extension "lnk"
String command = String command = "CMD /C start data\\<SomeWindowsShortcut.lnk>";
Runtime.getRuntime().exec(command);

What might cause this incompatibility and how do I fix it?

1

There are 1 best solutions below

0
On

Windows 7 and Windows XP appear to generate slightly incompatible file shortcuts.

Set aside for a moment the inelegance of both shell execution (of any kind) and programmatic execution of Windows shortcuts.

After some troubleshooting, it turns out that execution of Windows XP-generated shortcuts succeeded whereas those created or modified in Windows 7 (possibly Vista and other versions) yielded a "path not found" error.

The binary content of both shortcuts are different, though no comprehensive analysis of those differences was made.

The quick solution is to create the necessary shortcut in Windows XP. A longer-term and less horrifying solution is to eliminate use of shortcuts altogether.

I am curious about any information regarding the details of the shell execution incompatibility between shortcuts.