问题
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.
回答1:
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.
回答2:
You could use a Bat to Exe
converter from here:
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.
回答3:
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.
回答4:
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
).
回答5:
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.! :)
回答6:
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.
回答7:
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.
回答8:
Try BatToExe converter. It will convert your batch file to an executable, and allow you to set an icon for it.
回答9:
i recommand to use BAT to EXE converter for your desires
来源:https://stackoverflow.com/questions/15423/how-to-change-the-icon-of-bat-file-programmatically