Assign Icon to a Shortcut

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Stefan0
Posts: 6
Joined: 02 Jun 2023, 04:14

Assign Icon to a Shortcut

Post by Stefan0 » 02 Jun 2023, 04:35

Hello

I've been trying to set an icon but is not working for me.
In the following example, if I place an icon in C:\ for example, like so: C:\Icon.ico, my shortcut gets set with it.

Code: Select all

FileCreateShortcut, Notepad.exe, Shortcut.lnk, C:\, "%A_ScriptFullPath%", , C:\Icon.ico
But if I try:

Code: Select all

FileCreateShortcut, Notepad.exe, Shortcut.lnk, C:\, "%A_ScriptFullPath%", , C:\Windows\System32\SHELL32.dll, 128
It doesn't work. What am I missing?
Thanks

[Mod action: Moved topic to v1 section. The main section is for v2.]

User avatar
boiler
Posts: 16918
Joined: 21 Dec 2014, 02:44

Re: Assign Icon to a Shortcut

Post by boiler » 02 Jun 2023, 04:49

What is the 128 meant to be? The documentation says it must be the very first icon of a DLL, so you can’t pick a different icon number as if it were an icon file. And if that’s what it’s meant to be, your icon number parameter isn’t in the right place. Below is the command definition followed by the one you posted. Look carefully at where each parameter is supposed to be.

Code: Select all

FileCreateShortcut, Target, LinkFile , WorkingDir, Args, Description, IconFile, ShortcutKey, IconNumber, RunState
FileCreateShortcut, Notepad.exe, Shortcut.lnk, C:\, "%A_ScriptFullPath%", , C:\Windows\System32\SHELL32.dll, 128

User avatar
V0RT3X
Posts: 233
Joined: 20 May 2023, 21:59
Contact:

Re: Assign Icon to a Shortcut

Post by V0RT3X » 02 Jun 2023, 08:24

Might be the OP was mixing up with something like Menu, Tray, Icon, shell32.dll, 128? Although I'm not completely certain, but I think the number may be a different icon on different computers.

Stefan0
Posts: 6
Joined: 02 Jun 2023, 04:14

Re: Assign Icon to a Shortcut

Post by Stefan0 » 04 Jun 2023, 18:05

Hello guys, V0RT3X and boiler, sorry for my late reply.

When I submitted this question, I saw a message saying that my question would have to wait for forum approval. So I left thinking that I would receive an email letting me know when my question would be approved. But I never received anything, so I decided to join the forum today, and I was surprised to see that my question had been approved.

Now going back to my question, it supposed to be only one line of script, like so:

Code: Select all

FileCreateShortcut, Notepad.exe, Shortcut.lnk, C:\, "%A_ScriptFullPath%", , C:\Windows\System32\SHELL32.dll, 0
And the number of icon it could any from 0 to 179. I am not sure how many icons are in the Shell32.dll file.

My problem is the way I have my script, that's not the way it goes, I know I got it wrong, otherwise the shortcut created should show the icon assigned. In vb6 it works just fine the way I have it in AHK, but AHK does not see it the same way.
Thanks for your help guys, but am still stuck.

User avatar
boiler
Posts: 16918
Joined: 21 Dec 2014, 02:44

Re: Assign Icon to a Shortcut

Post by boiler » 04 Jun 2023, 18:33

You can solve it by extracting the desired icon from the DLL using a tool like resource hacker, then point to the icon file you create.

TAC109
Posts: 1111
Joined: 02 Oct 2013, 19:41
Location: New Zealand

Re: Assign Icon to a Shortcut

Post by TAC109 » 04 Jun 2023, 18:47

@Stefan0
I think that @boiler is trying to point out that you have your parameters in the wrong place for the command. Check the FileCreateShortcut documentation carefully and note that any optional parameters must still have their trailing commas entered, except after the last parameter you supply.

Cheers
My scripts:-
XRef - Produces Cross Reference lists for scripts
ReClip - A Text Reformatting and Clip Management utility
ScriptGuard - Protects Compiled Scripts from Decompilation
I also maintain Ahk2Exe

Stefan0
Posts: 6
Joined: 02 Jun 2023, 04:14

Re: Assign Icon to a Shortcut

Post by Stefan0 » 07 Jun 2023, 12:45

I have not been doing wrong, it is AHK that is not capable to handle it.

User avatar
boiler
Posts: 16918
Joined: 21 Dec 2014, 02:44

Re: Assign Icon to a Shortcut

Post by boiler » 07 Jun 2023, 12:51

No, for one thing, you had the parameter in the wrong place, so that's definitely just wrong syntax. And the documentation says you can't do what you are trying to do, so you can't say that it's not wrong. That's like saying I wasn't wrong in attempting to get my car to fly; it's just that the car is not capable of handling it.

Post Reply

Return to “Ask for Help (v1)”