<p>I'd like to know what's the way to actually set the icon of a <code>.bat</code> file to an arbitrary icon.
How would I go about doing that programmatically, independently of the language I may be using.</p>

[{'answer_id': 15435, 'author': 'Judge Maygarden', 'author_id': 1491, 'author_profile': 'https://Stackoverflow.com/users/1491', 'pm_score': 1, 'selected': False, 'text': "<p>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.</p>\n\n<p>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.</p>\n"}, {'answer_id': 15437, 'author': 'Sören Kuklau', 'author_id': 1600, 'author_profile': 'https://Stackoverflow.com/users/1600', 'pm_score': 7, 'selected': True, 'text': "<p>Assuming you're referring to MS-DOS batch files: as it is simply a text file with a special extension, a <code>.bat</code> file doesn't store an icon of its own.</p>\n\n<p>You can, however, create a shortcut in the <code>.lnk</code> format that stores an icon.</p>\n"}, {'answer_id': 856655, 'author': 'Joey', 'author_id': 73070, 'author_profile': 'https://Stackoverflow.com/users/73070', 'pm_score': 3, 'selected': False, 'text': '<p>The icon displayed by the Shell (Explorer) for batch files is determined by the registry key</p>\n\n<pre><code>HKCR\\batfile\\DefaultIcon\n</code></pre>\n\n<p>which, on my computer is</p>\n\n<pre><code>%SystemRoot%\\System32\\imageres.dll,-68\n</code></pre>\n\n<p>You can set this to any icon you like.</p>\n\n<p>This will however change the icons of all batch files (unless they have the extension <code>.cmd</code>).</p>\n'}, {'answer_id': 3965696, 'author': 'Naveen', 'author_id': 480092, 'author_profile': 'https://Stackoverflow.com/users/480092', 'pm_score': 2, 'selected': False, 'text': '<p>One of the way you can achieve this is:</p>\n\n<ol>\n<li>Create an executable Jar file</li>\n<li>Create a batch file to run the above jar and launch the desktop java application.</li>\n<li>Use Batch2Exe converter and covert to batch file to Exe.</li>\n<li>During above conversion, you can change the icon to that of your choice.(must of valid .ico file)</li>\n<li>Place the short cut for the above exe on desktop.</li>\n</ol>\n\n<p>Now your java program can be opened in a fancy way just like any other MSWindows apps.! :) </p>\n'}, {'answer_id': 4626066, 'author': 'd4rkcell', 'author_id': 566953, 'author_profile': 'https://Stackoverflow.com/users/566953', 'pm_score': 4, 'selected': False, 'text': '<p>You could use a <code>Bat to Exe</code> converter from here:</p>\n<p><a href="https://web.archive.org/web/20190304134631/http://www.f2ko.de/en/b2e.php" rel="nofollow noreferrer">https://web.archive.org/web/20190304134631/http://www.f2ko.de/en/b2e.php</a></p>\n<p>This will convert your batch file to an executable, then you can set the icon for the converted file.</p>\n'}, {'answer_id': 14687898, 'author': 'bli', 'author_id': 2039767, 'author_profile': 'https://Stackoverflow.com/users/2039767', 'pm_score': 4, 'selected': False, 'text': '<p>You can just create a shortcut and then right click on it -&gt; properties -&gt; change icon, and just browse for your desired icon.\nHope this help.</p>\n<p>To set an icon of a shortcut programmatically, see this article using <code>SetIconLocation</code>:</p>\n<p>How Can I Change the Icon for an Existing Shortcut?:</p>\n<p><a href="https://devblogs.microsoft.com/scripting/how-can-i-change-the-icon-for-an-existing-shortcut/" rel="noreferrer">https://devblogs.microsoft.com/scripting/how-can-i-change-the-icon-for-an-existing-shortcut/</a></p>\n<pre><code>Const DESKTOP = &amp;H10&amp;\nSet objShell = CreateObject(&quot;Shell.Application&quot;)\nSet objFolder = objShell.NameSpace(DESKTOP)\nSet objFolderItem = objFolder.ParseName(&quot;Test Shortcut.lnk&quot;)\nSet objShortcut = objFolderItem.GetLink\nobjShortcut.SetIconLocation &quot;C:\\Windows\\System32\\SHELL32.dll&quot;, 13\nobjShortcut.Save\n</code></pre>\n'}, {'answer_id': 18959298, 'author': 'Makaveli84', 'author_id': 2257124, 'author_profile': 'https://Stackoverflow.com/users/2257124', 'pm_score': 2, 'selected': False, 'text': '<p>Try BatToExe converter. It will convert your batch file to an executable, and allow you to set an icon for it.</p>\n'}, {'answer_id': 48553229, 'author': 'jmkuss', 'author_id': 9297201, 'author_profile': 'https://Stackoverflow.com/users/9297201', 'pm_score': 3, 'selected': False, 'text': '<p>If you want an icon for a batch file,\nfirst create a link for the batch file as follows</p>\n\n<p>Right click in window folder where you want the link\nselect New -> Shortcut, then specify where the .bat file is.</p>\n\n<p>This creates the .lnk file you wanted.\nThen you can specify an icon for the link,\non its properties page.</p>\n\n<p>Some nice icons are available here:</p>\n\n<p>%SystemRoot%\\System32\\SHELL32.dll</p>\n\n<p>Note For me on Windows 10:\n%SystemRoot% == C:\\Windows\\ </p>\n\n<p>More Icons are here:\nC:\\Windows\\System32\\imageres.dll</p>\n\n<p>Also you might want to have the first line\nin the batch file to be "cd .."\nif you stash your batch files in a bat subdirectory\none level below where your shortcuts,  are supposed to execute.</p>\n'}, {'answer_id': 49347358, 'author': 'sudip ghimire', 'author_id': 9511700, 'author_profile': 'https://Stackoverflow.com/users/9511700', 'pm_score': -1, 'selected': False, 'text': '<p>i recommand to use BAT to EXE converter for your desires </p>\n'}, {'answer_id': 64758203, 'author': 'npocmaka', 'author_id': 388389, 'author_profile': 'https://Stackoverflow.com/users/388389', 'pm_score': 1, 'selected': False, 'text': '<p>try with <a href="https://github.com/npocmaka/batch.scripts/blob/master/hybrids/jscript/shortcutJS.bat" rel="nofollow noreferrer">shortcutjs.bat</a> to create a shortcut:</p>\n<pre><code>call shortcutjs.bat -linkfile mybat3.lnk -target &quot;%cd%\\Ascii2All.bat&quot; -iconlocation &quot;%SystemRoot%\\System32\\SHELL32.dll,77&quot;\n</code></pre>\n<p>you can use the -iconlocation switch to point to a icon .</p>\n'}, {'answer_id': 70447573, 'author': 'Lev K.', 'author_id': 2498399, 'author_profile': 'https://Stackoverflow.com/users/2498399', 'pm_score': 0, 'selected': False, 'text': '<p>You may use a program like BAT to EXE converter for example that one: <a href="https://www.battoexeconverter.com/#downloadbattoexe" rel="nofollow noreferrer">link</a></p>\n<p><a href="https://i.stack.imgur.com/FOjzf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FOjzf.png" alt="enter image description here" /></a></p>\n<p>This program permits you to add your custom icon.</p>\n'}]
['https://Stackoverflow.com/questions/15423', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/883/']