Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^3: Changing Windows Shortcut Icons

by Albannach (Monsignor)
on Jul 12, 2004 at 15:02 UTC ( [id://373620]=note: print w/replies, xml ) Need Help??


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

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

Replies are listed 'Best First'.
Re^4: Changing Windows Shortcut Icons
by bbfu (Curate) on Jul 15, 2004 at 08:24 UTC

    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.

    bbfu
    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?
        go to control pannel the folder options - the option to change it somewhere there!
        Here's your answer: http://www.lytebyte.com/2007/06/27/how-to-show-and-hide-file-extensions-in-windows/

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-03-19 03:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found