C++ 如何更改可执行文件的属性?(视窗)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1022449/
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-08-27 18:25:58  来源:igfitidea点击:

How to change an executable's properties? (Windows)

c++windowspropertiesexeexecutable

提问by merkuro

When I create a .exe, I can right click it and go to properties->details. Then I get a list like:

当我创建一个 .exe 时,我可以右键单击它并转到属性->详细信息。然后我得到一个列表:

File Description | 
Type             | Application
File Version     | 
Product Name     | 
Product Version  |
Copyright        | 
Size             | 18.0 KB
Date Modified    | 6/16/2009 8:23 PM
Language         |
File Description | 
Type             | Application
File Version     | 
Product Name     | 
Product Version  |
Copyright        | 
Size             | 18.0 KB
Date Modified    | 6/16/2009 8:23 PM
Language         |

How do I change these properties? (And on a side note, is there a way to change the icon?)

如何更改这些属性?(顺便说一句,有没有办法更改图标?)

回答by merkuro

If you are using C/Win32 you can add something like this to your project encapsulated in a *.rc (resource) file:

如果您使用的是 C/Win32,您可以将这样的内容添加到封装在 *.rc(资源)文件中的项目中:

VS_VERSION_INFO VERSIONINFO
 FILEVERSION    0,0,0,2
 PRODUCTVERSION 0,0,0,2
 FILEFLAGSMASK 0x3fL
 #ifdef _DEBUG
 FILEFLAGS 0x1L
 #else
 FILEFLAGS 0x0L
 #endif
 FILEOS 0x4L
 FILETYPE 0x1L
 FILESUBTYPE 0x0L
{
    BLOCK "StringFileInfo"
    { 
        BLOCK "040904b0"
        {
            VALUE "Comments",         "comment
$ rcedit MyApp.exe --set-version-string FileDescription "My Awesome App"
" VALUE "CompanyName", "comment
using System.Reflection;  // Needed to get to the attributes.

[assembly:AssemblyTitle("My File Description")]
[etc.]
" VALUE "FileDescription", "base file##代码##" VALUE "FileVersion", "0.0.0.2 TP##代码##" VALUE "InternalName", "testTP##代码##" VALUE "LegalCopyright", "none##代码##" VALUE "OriginalFilename", "test.exe##代码##" VALUE "ProductName", "test##代码##" VALUE "ProductVersion", "0.0.0.2 TP##代码##" } } BLOCK "VarFileInfo" { VALUE "Translation", 0x409, 1200 } }

回答by LarryDavid

Very easy if you are using visual studio:

如果您使用的是 Visual Studio,则非常简单:

  • Right click on the 'Resource Files' folder in the project
  • Click 'Add' then 'Resource'
  • Choose 'Version' from the pop-up dialog
  • 右键单击项目中的“资源文件”文件夹
  • 单击“添加”,然后单击“资源”
  • 从弹出对话框中选择“版本”

You can then double click on the file to open it in Visual Studio, and you get a handy editor to change the values.

然后您可以双击该文件在 Visual Studio 中打开它,您将获得一个方便的编辑器来更改值。

Your values are then automatically linked in to the EXE.

然后您的值会自动链接到 EXE。

回答by a paid nerd

If you want to change the FileDescription or any other version resource string on a compiled executable, rcedit(a small open-source tool) does it pretty easily:

如果您想更改已编译的可执行文件上的 FileDescription 或任何其他版本资源字符串,rcedit(一个小型​​开源工具)可以很容易地完成:

##代码##

回答by arbiter

This is simple file version info resource. For already existent files you can edit this information with any resource editor (for example Resource Hacker, it is outdated but still good). You can change icon this way too.

这是简单的文件版本信息资源。对于已经存在的文件,您可以使用任何资源编辑器编辑此信息(例如Resource Hacker,它已经过时但仍然很好)。您也可以通过这种方式更改图标。

If you create your own application, then setting it depends on tool you are using. For example in Visual Studio you must look into project properties.

如果您创建自己的应用程序,那么设置它取决于您使用的工具。例如,在 Visual Studio 中,您必须查看项目属性。

回答by yoyo

For .NET, google for "setting assembly attributes" for information on what attributes are available. You then use the attributes like so ...

对于 .NET,请搜索“设置程序集属性”以获取有关可用属性的信息。然后你使用这样的属性......

##代码##