Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the icon of .bat file programmatically?

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.

like image 954
SaM Avatar asked Aug 19 '08 00:08

SaM


People also ask

How do I change the icon of an EXE file?

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.”

How do I create a custom .bat file?

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.


3 Answers

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.

like image 149
Sören Kuklau Avatar answered Oct 01 '22 12:10

Sören Kuklau


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 
like image 31
bli Avatar answered Oct 01 '22 12:10

bli


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.

like image 24
d4rkcell Avatar answered Oct 01 '22 14:10

d4rkcell