windows 如何以编程方式更改 .bat 文件的图标?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15423/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:10:46  来源:igfitidea点击:

How to change the icon of .bat file programmatically?

windowsiconsbatch-file

提问by SaM

I'd like to know what's the way to actually set the icon of a .batfile to an arbitrary icon. How would I go about doing that programmatically, independently of the language I may be using.

我想知道将.bat文件的图标实际设置为任意图标的方法是什么。我将如何以编程方式执行此操作,而与我可能使用的语言无关。

采纳答案by S?ren Kuklau

Assuming you're referring to MS-DOS batch files: as it is simply a text file with a special extension, a .batfile doesn't store an icon of its own.

假设您指的是 MS-DOS 批处理文件:因为它只是一个带有特殊扩展名的文本文件,.bat文件不存储自己的图标。

You can, however, create a shortcut in the .lnkformat that stores an icon.

但是,您可以.lnk以存储图标的格式创建快捷方式。

回答by d4rkcell

You could use a Bat to Execonverter from here:

您可以Bat to Exe从这里使用转换器:

http://www.f2ko.de/en/b2e.php

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.

这会将您的批处理文件转换为可执行文件,然后您可以为转换后的文件设置图标。

回答by bli

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.

您可以创建一个快捷方式,然后右键单击它-> 属性-> 更改图标,然后浏览您想要的图标。希望这有帮助。

回答by Joey

The icon displayed by the Shell (Explorer) for batch files is determined by the registry key

Shell (Explorer) 为批处理文件显示的图标由注册表项决定

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

但是,这将更改所有批处理文件的图标(除非它们具有扩展名.cmd)。

回答by Naveen

One of the way you can achieve this is:

实现这一目标的方法之一是:

  1. Create an executable Jar file
  2. Create a batch file to run the above jar and launch the desktop java application.
  3. Use Batch2Exe converter and covert to batch file to Exe.
  4. During above conversion, you can change the icon to that of your choice.(must of valid .ico file)
  5. Place the short cut for the above exe on desktop.
  1. 创建一个可执行的 Jar 文件
  2. 创建一个批处理文件来运行上述 jar 并启动桌面 java 应用程序。
  3. 使用 Batch2Exe 转换器并将批处理文件转换为 Exe。
  4. 在上述转换过程中,您可以将图标更改为您选择的图标。(必须是有效的 .ico 文件)
  5. 将上述exe的快捷方式放在桌面上。

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

现在您的 Java 程序可以像任何其他 MSWindows 应用程序一样以一种奇特的方式打开。!:)

回答by jmkuss

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.

右键单击要链接的窗口文件夹,选择新建 -> 快捷方式,然后指定 .bat 文件所在的位置。

This creates the .lnk file you wanted. Then you can specify an icon for the link, on its properties page.

这将创建您想要的 .lnk 文件。然后,您可以在其属性页面上为该链接指定一个图标。

Some nice icons are available here:

一些不错的图标在这里可用:

%SystemRoot%\System32\SHELL32.dll

%SystemRoot%\System32\SHELL32.dll

Note For me on Windows 10: %SystemRoot% == C:\Windows\

注意对于我在 Windows 10 上: %SystemRoot% == C:\Windows\

More Icons are here: C:\Windows\System32\imageres.dll

更多图标在这里: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.

此外,如果您将批处理文件存储在 bat 子目录中,那么您可能希望批处理文件中的第一行是“cd ..”,该子目录低于您的快捷方式应该执行的位置。

回答by Makaveli84

Try BatToExe converter. It will convert your batch file to an executable, and allow you to set an icon for it.

试试 BatToExe 转换器。它会将您的批处理文件转换为可执行文件,并允许您为其设置图标。

回答by Judge Maygarden

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.

我假设你在谈论 Windows,对吧?我不相信您可以直接更改批处理文件的图标。图标嵌入在 .EXE 和 .DLL 文件中,或由 .LNK 文件指向。

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.

您可以尝试更改文件关联,但该方法可能因您使用的 Windows 版本而异。这与 XP 中的注册表有关,但我不确定 Vista。

回答by sudip ghimire

i recommand to use BAT to EXE converter for your desires

我建议使用 BAT 到 EXE 转换器来满足您的需求