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.
Right-click the original EXE file (not the copy you made) and choose “Open using Resource Hacker.” In the Resource Hacker window, select the “Icon” folder in the left pane. Click the “Action” menu and then select “Replace Icon.”
To create a Windows batch file, follow these steps: Open a text file, such as a Notepad or WordPad document. Add your commands, starting with @echo [off], followed by, each in a new line, title [title of your batch script], echo [first line], and pause. Save your file with the file extension BAT, for example, test.
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.GetLink objShortcut.SetIconLocation "C:\Windows\System32\SHELL32.dll", 13 objShortcut.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With