4

I'm writing a launcher/installer for end users which, among other things, will optionally generate shortcuts in the Start Menu and/or on the Desktop.

Ideally, I'd like these shortcuts to support these scenarios:

  • the user changes the displayed name to their liking;
  • the user moves or copies the shortcut somewhere else (e.g., to Quick Launch);
  • the launcher later on discovers that it needs to update the icon and/or target location of the shortcut.

Right now, the launcher isn't smart about this — if it already finds a shortcut with the current name, it will leave it alone; if it doesn't, it will create a new one. Thus, if something about the shortcut has changed, either by the user, or by the launcher's database, you now end up with one that's current, and one that's not.

In order to properly track shortcuts including moves and copies and, I'm wondering if putting an NTFS alternate data stream "FoobarInstaller.Shortcut" in each of these shortcuts which simply contains a UUID is a viable option. I'd then ideally like to scan the entire user directory tree (or perhaps just typical locations like Desktop, Start Menu and Quick Launch) for files with the stream, and see if I need to apply updates to those.

What I don't know is if this is efficient. Does NTFS/Win32 feature an API to efficiently find all files with a certain ADS by name?

Sören Kuklau
  • 19,454
  • 7
  • 52
  • 86

1 Answers1

0

NTFS has a way of uniquely identifying files: Object IDs. They do not change on rename and you can lookup files by id. You could keep a database of object ids in a well-known place (e.g. in the users app data directory). Then you can locate all existing shortcuts in constant time.

I believe some Windows "moved shortcut repair" feature uses this.

usr
  • 168,620
  • 35
  • 240
  • 369
  • I considered that, but what happens when a shortcut has been copied? Can I get the offshoots of an object ID? – Sören Kuklau Feb 25 '15 at 20:08
  • No since the OS is unaware of file copies. A copy is a read followed by a write to an unrelated file. – usr Feb 25 '15 at 20:18
  • Whether ADS'es are copied or not is at the discretion of the program doing the copying. Usually, the CopyFile API is used which does copy streams as well. A manual copy loop would almost certainly not do that. Archive programs also do not respect ADS'es. So you might get lucky in the common case. – usr Feb 25 '15 at 20:30
  • Right — in the typical case of a user copying a shortcut somewhere using Windows Explorer, the ADSes should be copied as well. In case of archivers, backups, etc., it wouldn't matter much for my use case. – Sören Kuklau Feb 25 '15 at 20:57