tags:

views:

7893

answers:

6

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.

A: 

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.

Judge Maygarden
+4  A: 

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.

Sample code:

Sören Kuklau
+1  A: 

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

Joey
A: 

owhh.. so.. that's impossible for us to make an icon for .bat file which is portable? i mean, i wanna make a .bat file which is portable. and i dont know how to implement this.. thx aniway.

if there is any answer or suggestion, just send it to my email: [email protected]

cheers..

mishbah
A: 

To do this I recommend two programs Resource Hacker and Replacer if you plan on changing the icon group in the dynamic link library file(.dll). To change the icon of an individual batch script make a shortcut and change the shortcuts icon or a Bat to Exe Converter would allow you to select an icon for the converted compressed executable program(exe).

anonymous
A: 

One of the way you can achieve this is: -> create an executable Jar file -> create a batch file to run the above jar and launch the desktop java application. -> use Batch2Exe converter and covert to batch file to Exe. -> during above conversion, you can change the icon to that of your choice.(must of valid .ico file) -> place the short cut for the above exe on desktop.

now your java program can be opened in a fancy way just like any other MSWindows apps.! :)

Naveen