InstallShield制作安装包-获取安装路径并写入到配置文件

很多时候我们在做安装包的时候,会发现需要将你所设置的内容是需要写入到安装程序的配置文件里面的.

在用installshield制作安装包的时候我们发现有一个WriteProfString可以为我们所用。

The WriteProfString function writes a profile string to an .ini file. Depending on the values passed to WriteProfString, it can create a section, delete an entire section, create a unique KEY=VALUE entry, delete a KEY=VALUE entry, or update a key’s value.

我们可以使用WriteProfString函数,将值写入到配置文件某一行。

注意事项:

  • To write an integer value to an .ini file, call WriteProfInt instead.
  • Use the AddProfString and ReplaceProfString functions when you want to modify the System.ini file.
  • Changes made to .ini files can be logged for uninstallation. However, there are some important restrictions to be aware of. For more information, see Uninstalling Initialization (.ini) File Entries.
  • WriteProfString uses the Windows API WritePrivateProfileString to access the .ini file. Therefore, its functionality is limited by the functionality provided by the Windows API. Consult Windows programming documentation for more information on .ini files.
  • Windows caches .ini files, which can cause a delay in writing changes to the specified files. This in turn can interfere with subsequent file operations, such as calls to CopyFile and XCopyFile. Therefore, you should flush the cache buffer after using WriteProfString if you are using file operations shortly afterward. Simply call WriteProfString with null parameters to force Windows to write the data to the .ini file immediately:
  • WriteProfString (“C:\Test.ini”, “Windows”, “KeyboardDelay”, “100”);

    WriteProfString (“”, “”, “”, “”); // null string for all four parameters

    // CopyFile should now have access to updated file. CopyFile (“C:\Test.ini”, “C:\Temp\Test.ini”);

官方的说明文档写得很多下面实际例子来一个

首先我们做一下准备工作:

1.我们首先要获取本次安装程序的路径

2.我需要安装路径的值赋予到安装路径的配置文件config.ini里面Control这项下面的Path

WriteProfString ( TARGETDIR^”\Server\config.ini”, “Control”, “Path”, TARGETDIR^”\Server” );

看只要一行代码就能解决问题

TARGETDIR^”\Server\config.ini                   //是我程序的安装路径下的配置文件

Control                                                         //我配置文件里面的一个项

Path                                                            //是Control 项里面的键值,我要将安装路径赋予给他

TARGETDIR^”\Server                               //是我程序的安装路径

TARGETDIR是用户选择的安装路径Server是程序指定的目录

今天这个貌似太简单了点…………..

人懒就写这么多了,有空继续写点……………

《InstallShield制作安装包-获取安装路径并写入到配置文件》有0个想法

  1. Pingback: 阅读

发表评论

电子邮件地址不会被公开。 必填项已用*标注