Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Changing Windows Shortcut Icons

by mdog (Pilgrim)
on Jul 08, 2004 at 17:48 UTC ( #372879=perlquestion: print w/ replies, xml ) Need Help??
mdog has asked for the wisdom of the Perl Monks concerning the following question:

Brethern --

I've done some searching on the Net and haven't figure out to do the following:

Take a windows shortcut (let say on the desktop) and change it's icon using perl (without using Win32::GuiTest).

I want the icon to change without having perl needing to take control of the mouse / keyboard (Win32::GuiTest).

So is there anyway to do this behind the scenes?

Thanks,
mdog

Comment on Changing Windows Shortcut Icons
Re: Changing Windows Shortcut Icons
by EdwardG (Vicar) on Jul 08, 2004 at 21:32 UTC

    You could get to the icon via Windows Script Host, like this script does.

     

Re: Changing Windows Shortcut Icons
by Albannach (Prior) on Jul 08, 2004 at 21:46 UTC
    Have a look at Win32::Shortcut (part of libwin32) which you probably already have if you installed ActiveState. Something like:
    my $shortcut = Win32::Shortcut->new($file); $shortcut->{IconLocation} = 'C:\Perl\bin\perl.exe'; $shortcut->{IconNumber} = 0; $shortcut->Save($file);
    should do the trick. 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'd like to be able to assign to an luser

      Many, many thanks! This is exactly what I was looking for...I should have checked CPAN but I didn't think there would be anything specific for windows and shortcuts. Goes to show how much I know.

      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?

      bbfu
      Black flowers blossom
      Fearless on my breath

        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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://372879]
Approved by Crackers2
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2014-04-20 11:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls