Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^2: Changing Windows Shortcut Icons

by bbfu (Curate)
on Jul 08, 2004 at 22:59 UTC ( #372986=note: print w/ replies, xml ) Need Help??

in reply to Re: Changing Windows Shortcut Icons
in thread Changing Windows Shortcut Icons

Now if you can tell me how to determine which files in a given list are in fact shortcuts (apart from testing the ShortcutPath using Win32::Shortcut) then I'd be interested to hear it!

I could be missing something, but can't you tell simply from the '.lnk' extension?

Black flowers blossom
Fearless on my breath

Replies are listed 'Best First'.
Re^3: Changing Windows Shortcut Icons
by Albannach (Prior) on Jul 12, 2004 at 15:02 UTC
    Thanks! It appears (through some experiments on several different versions of Windows - sorry for the delay) that having the extension 'lnk' is sufficient proof that a file is indeed a shortcut file. I had thought of that but assumed (foolishly it seems) that one could re-name a shortcut without destroying the shortcutting capability. It seems that this is not the case - you can't rename a shortcut to eliminate the '.lnk' (short of editing the directory I imagine).

    However: if you rename any file to add '.lnk', the file seems to be permanently changed (since you can't remove the '.lnk') to a shortcut, though it's content is retained and can still be manipulated. In this case, the shortcut properties are inaccessible which makes me think that it isn't really a shortcut after all. Now, if you use Win32::Shortcut's Save() on such a file that isn't really a shortcut, its contents are then destroyed and replaced with the guts of a standard .lnk file and it becomes a real shortcut. Just to be weirder, I tried Save() on a normal file without '.lnk', and it too had it's content replaced, but the Explorer didn't recognise it as a shortcut as the extension was not 'lnk'. I think I'll stop now! It would be better if it were simply impossible to add '.lnk' to an existing normal file.

    I'd like to be able to assign to an luser

      Yeah, unlike *nix, Windows relies pretty heavily on file extensions; a hold-over from it's DOS days. And since there was no capacity for symlink-style referencing in the old FAT32 system, MS adopted the .lnk "special" extension. Personally, I think they should've added real symlinking when they came up with, or switched to, NTFS. But I guess "Shortcuts" worked well enough for them.

      Windows treats certain file extensions (and file names) specially. Obviously .lnk is one of them, but CLSID's-as-file-extensions are another special case. (That's how the Recycle Bin, My Computer, etc, icons are handled on the desktop. Well, not really, but it does allow you to add those special "icons" to any folder, not just the desktop.)

      Special file extensions are never shown in Windows Explorer, even if you have the "Hide known extensions" option disabled. Also, when renaming a file with a special extension, Explorer doesn't let you change the extension. However, you can still see and change the extension via the command line, since it doesn't treat the extensions specially. Adding a .lnk extension to a non-shortcut file doesn't actually change the file data in any way, of course, but it does change how Explorer displays and manipulates the file. Similarly, removing the .lnk extension from an actual shortcut will cause Windows to no longer recognize it as a shortcut, but it still contains the binary data that comprises a "Windows Shortcut."

      In short, Explorer (mostly) only cares whether the file has a .lnk extension or not, while Windows only cares whether the file can be successfully read by the LoadShortcutFile() (or whatever it's called) system call.

      Black flowers blossom
      Fearless on my breath

        I know this thread is very old, but for some reason on my XP machine, I can SEE the .lnk extensions on all my shortcuts regardless of where they are. I remember intentionally enabling this but now I can't fix it. Anyone know how I can restore their previously hidden state?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://372986]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2016-07-29 11:14 GMT
Find Nodes?
    Voting Booth?
    What is your favorite alternate name for a (specific) keyboard key?

    Results (260 votes). Check out past polls.