Windows shortcut errors stop xojo processing

When i read a list of files in a windows folder and come over a shortcut that has a missing link. Windows throws up a window (even in a console app) and stops the app from continuing to the next file. Is there a way to stop this.

What is the “thrown up” window saying exactly ?

These errors seem to come from the shell.

What is the code you are using to list the files ? In pure Xojo these errors should be trappable.

You can use FolderItem.TrueChild or FolderItem.TrueItem to prevent Windows from trying to resolve the shortcut target. Instead you’ll get a reference to the shortcut file itself rather than its target.

I think he is doing it with a shell. A missing file would probably trigger a NOE in pure Xojo, and the error can be avoided by checking .exists.
look for “SetErrorMode”

I’ve seen this recently. FolderItem.Name on a shortcut, where the target file has been deleted. I was building a list of files in a folder, when an invalid shortcut is touched Windows throws a popup asking the user to locate the missing file. This happens even in a Windows Service app - since its a service it can’t generate the popup and just hangs. Windows Server 2012R2.

You can use FolderItem.Alias to detect a shortcut, but it has the same problem. If you “touch” an invalid shortcut, Windows throws the popup.

I was thinking this is a Windows bug since a service shouldn’t be able to get itself stuck like that. It makes sense in some desktop applications to prompt for this, but for anything that needs to run in the background it’s trouble.

Do you check folderItem.exists before trying to open the file ? This should prevent the error.

This. None of the other stuff will help that much.

I’m running into this problem using Xojo.IO.FolderItem, which does not use TrueChild or TrueItem. I tried using If not FolderItem.IsAlias then but that does not prevent the Missing Shortcut errors in Windows.

In place of TrueItem, use Children with ResolveAlias set to False. In place of TrueChild, use Child with ResolveAlias set to false.

I tried that but it didn’t stop the Missing Shortcut error messages.

I’m sorry for bumping an old thread, but I was wondering whether anybody found a solution to trapping/handling the error thrown up by assigning a shortcut with missing files to a Xojo FolderItem?

Are you using FolderItem or Xojo.IO.FolderItem ?

Classic FolderItem

Using FolderItem.TrueItem instead of FolderItem.Item will return the actual .lnk file rather than the OS trying to resolve it so it wont show the dialog.

As for resolving where the actual link points without showing the dialog, that is another and more tricky matter. Do you need that?

Thank you Julian. Yes I need to resolve where the shortcut/link actually points to without showing the dialog, check whether that location is still valid and whether the file still exists, and then access the file. I can do all that already for files which are not shortcuts, and it also works for valid shortcuts. The issue occurs when the shortcut is invalid. :slight_smile:

Do you have MBS plugins? I believe what you need is in there and would save a bit of work.

The format of a .lnk file is published here:

You could read the file, extract the path, and check to see if it exists.