How to change the icon of .bat file programmatically?
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 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.GetLinkobjShortcut.SetIconLocation "C:\Windows\System32\SHELL32.dll", 13objShortcut.Save
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.