I\'d like to know what\'s the way to actually set the icon of a .bat
file to an arbitrary icon.
How would I go about doing that programmatically, independently of t
I'll assume you are talking about Windows, right? I don't believe you can change the icon of a batch file directly. Icons are embedded in .EXE and .DLL files, or pointed to by .LNK files.
You could try to change the file association, but that approach may vary based on the version of Windows you are using. This is down with the registry in XP, but I'm not sure about Vista.
You can just create a shortcut and then right click on it -> properties -> change icon, and just browse for your desired icon. Hope this help.
To set an icon of a shortcut programmatically, see this article using SetIconLocation
:
How Can I Change the Icon for an Existing Shortcut?:
https://devblogs.microsoft.com/scripting/how-can-i-change-the-icon-for-an-existing-shortcut/
Const DESKTOP = &H10&
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(DESKTOP)
Set objFolderItem = objFolder.ParseName("Test Shortcut.lnk")
Set objShortcut = objFolderItem.GetLink
objShortcut.SetIconLocation "C:\Windows\System32\SHELL32.dll", 13
objShortcut.Save
try with shortcutjs.bat to create a shortcut:
call shortcutjs.bat -linkfile mybat3.lnk -target "%cd%\Ascii2All.bat" -iconlocation "%SystemRoot%\System32\SHELL32.dll,77"
you can use the -iconlocation switch to point to a icon .
If you want an icon for a batch file, first create a link for the batch file as follows
Right click in window folder where you want the link select New -> Shortcut, then specify where the .bat file is.
This creates the .lnk file you wanted. Then you can specify an icon for the link, on its properties page.
Some nice icons are available here:
%SystemRoot%\System32\SHELL32.dll
Note For me on Windows 10: %SystemRoot% == C:\Windows\
More Icons are here: C:\Windows\System32\imageres.dll
Also you might want to have the first line in the batch file to be "cd .." if you stash your batch files in a bat subdirectory one level below where your shortcuts, are supposed to execute.
i recommand to use BAT to EXE converter for your desires
The icon displayed by the Shell (Explorer) for batch files is determined by the registry key
HKCR\batfile\DefaultIcon
which, on my computer is
%SystemRoot%\System32\imageres.dll,-68
You can set this to any icon you like.
This will however change the icons of all batch files (unless they have the extension .cmd
).