简体   繁体   English

永久自定义文件夹图标与InnoSetup在任何计算机中

[英]Permanent customized folder icons with InnoSetup in any computer

I have modified some folder icons and I am including these folders in my InnoSetup installation. 我修改了一些文件夹图标,我在InnoSetup安装中包含了这些文件夹。 The problem is that once my program is installed, my customized folder icons are gone and what I see is just the oldfashioned "yellow" Windows folder icons. 问题是,一旦我的程序安装完毕,我的自定义文件夹图标就会消失,我看到的只是旧式的“黄色”Windows文件夹图标。

EDIT 编辑

The answer was provided by the user TLama. 答案由用户TLama提供。 It worked in my computer at first. 它起初在我的电脑上工作。 I had some problems with different Windows versions at different computers. 我在不同的计算机上遇到了不同Windows版本的问题。 I will write now my working code after having tried sucessfully in several computer systems. 在几个计算机系统中成功试用后,我现在将编写我的工作代码。

Icons used: 使用的图标:

  • Ico1.ico Ico1.ico
  • Ico2.ico Ico2.ico
  • Ico3.ico Ico3.ico

Modified folder icons: 修改文件夹图标:

  • c:\\FDR1 C:\\ FDR1
  • c:\\FDR2\\FDR3 C:\\ FDR2 \\ FDR3

Step 1: 步骤1:

I have used the software "Folder icon changer" to have my icon in place for the three folders I wanted changed. 我已经使用软件“文件夹图标更换器”为我想要更改的三个文件夹设置了我的图标。 You may use any other free software too. 您也可以使用任何其他免费软件。 After execution, a desktop.ini appeared in each of the newly changed icon folders. 执行后,每个新更改的图标文件夹中都会出现desktop.ini。 For instance, the FDR1 has the content: 例如,FDR1具有以下内容:

[.Shellclassinfo]
Iconfile=F:\Resource\Icons\Ico1.ico
Iconindex= 0

Step 2: 第2步:

I have then erased the path above and saved "Ico1.ico" into the directory "c:\\FDR1" I had just modified : 然后我删除了上面的路径并将“Ico1.ico”保存到我刚修改的目录“c:\\ FDR1”中:

[.Shellclassinfo]
Iconfile=Ico1.ico
Iconindex= 0

I did the same for the Ico2.ico (inside the FDR2) and the Ico3.ico (inside the FDR3). 我为Ico2.ico(FDR2内部)和Ico3.ico(FDR3内部)做了同样的事情。 The "Icon1, 2 and 3" and "desktop.ini" file attributes were all set to hidden. “Icon1,2和3”和“desktop.ini”文件属性都设置为隐藏。 But, it is important NOT to set the icon properties to "read only". 但是,重要的是不要将图标属性设置为“只读”。

Step 3: 第3步:

Inside Inno repeat TLama's suggestion. Inno内部重复了TLama的建议。

#define OutputDirectory_1 "c:\FDR1"
#define OutputDirectory_2 "c:\FDR2"
#define OutputDirectory_3 "c:\FDR2\FDR3"

[Dirs]
Name: {#OutputDirectory_1}; Attribs: system
Name: {#OutputDirectory_2}; Attribs: system
Name: {#OutputDirectory_3}; Attribs: system

[Files]
Source: "c:\FDR1\Ico1.ico"; DestDir: {#OutputDirectory_1}; Attribs: hidden system
Source: "c:\FDR2\Ico2.ico"; DestDir: {#OutputDirectory_2}; Attribs: hidden system
Source: "c:\FDR2\FDR3\Ico3.ico"; DestDir: {#OutputDirectory_3}; Attribs: hidden system

Step 4: 第4步:

Compile ! 编译!

Now, your folder icons will permanently work in any computer and system !! 现在,您的文件夹图标将永久在任何计算机和系统中工作!

Your target folder should have either read only or system attribute configured. 您的目标文件夹应该具有只读或系统属性配置。 To create such folder you can use, like Miral mentioned, [Dirs] section and its attributes. 要创建这样的文件夹,您可以像Miral所提到的那样使用[Dirs]部分及其属性。 This will have an advantage, that after you run the installation process, InnoSetup automatically notifies Shell about changes, so the folder icon will be changed without an extra notification function call. 这将有一个优势,即在您运行安装过程后,InnoSetup会自动通知Shell有关更改的信息,因此文件夹图标将在没有额外通知函数调用的情况下进行更改。

; this is a defined preprocessor variable used to simplify the script
; management; this variable contains the path, where the icon will be 
; applied (it's used twice in a script, so it's easier to manage that
; from one place)
#define OutputDirectory "d:\TargetDirectory"

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output

[Files]
; here you need to use "hidden" and "system" values in Attribs parameter
; to include into the Desktop.ini file hidden and system file attributes
Source: "Desktop.ini"; DestDir: {#OutputDirectory}; Attribs: hidden system

[Dirs]
; here you need to use either "readonly" or "system" value in Attribs parameter
; to setup to the output directory read only or system file directory attribute
Name: {#OutputDirectory}; Attribs: readonly

Important: 重要:

Don't forget that you have to compile the script using CTRL + F9 before running, whenever you change the content of your input Desktop.ini file as well as when you change the value of the preprocessor path variable (I've been missing this few times and then wondering about the setup package content). 不要忘记在运行之前必须使用CTRL + F9编译脚本,每当您更改输入Desktop.ini文件的内容以及更改预处理器路径变量的值时(我一直在想这个)几次,然后想知道安装包内容)。

In order to activate custom folder icons you have to programmatically set the "read-only" attribute of the folder containing the desktop.ini file. 要激活自定义文件夹图标,您必须以编程方式设置包含desktop.ini文件的文件夹的“只读”属性。 (You can't do this from Explorer, but you can via the command line and from Inno.) (您不能从资源管理器中执行此操作,但您可以通过命令行和Inno。)

[Dirs]
Name: {app}; Attribs: readonly

Note that the path inside the desktop.ini file must be valid on the user's filesystem; 请注意, desktop.ini文件中的路径必须在用户的文件系统上有效; you may want to use an [Ini] entry to create or modify this file to suit the installation path. 您可能希望使用[Ini]条目来创建或修改此文件以适合安装路径。

(This doesn't actually make the folder read-only -- this attribute is treated differently on folders by Windows because only files can meaningfully be read-only.) (这实际上并不使文件夹成为只读 - Windows对文件夹的处理方式不同,因为只有文件才能有意义地为只读文件。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM