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 the language I may be using.
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 the language I may be using.
Assuming you're referring to MS-DOS batch files: as it is simply a text file with a special extension, a .bat file doesn't store an icon of its own.
You can, however, create a shortcut in the .lnk format that stores an icon.
You could use a Bat to Exe converter from here:
https://web.archive.org/web/20190304134631/http://www.f2ko.de/en/b2e.php
This will convert your batch file to an executable, then you can set the icon for the converted file.
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).
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'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.
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 .
You may use a program like BAT to EXE converter for example that one: link
This program permits you to add your custom icon.