分类:
2009-03-27 16:22:41
InstallShield 2009 » InstallScript Language Reference
The AddProfString function unconditionally adds a profile string to an .ini file. Use AddProfString only to add non-unique keys, such as those found in the [386Enh] section of the System.ini file (device = ...). AddProfString adds the line KEY=VALUE to the end of the specified .ini file section. It does not replace or update an existing key. To update an existing non-unique key, call . To add a unique key or to update an existing unique key's value in an .ini file, call .
AddProfString ( szFileName, szSectionName, szKeyName, szValue );
Parameter |
Description |
---|---|
szFileName |
Specifies the name of the .ini file to which the profile string is to be added. If szFileName is unqualified (that is, if a drive designation and path are not included), InstallShield searches for the file in the Windows folder. If the file does not exist, it is created in the specified folder; if a path is not included in file name, the file is created in the Windows folder. If the file name is qualified with a path that does not exist, AddProfString fails. |
szSectionName |
Specifies the name of a section in the .ini file section. The profile string is inserted at the end of that section. If the section does not exist, InstallShield creates it. The section name should not be enclosed within delimiting brackets ( [ ] ). Note that the profile string is inserted even if the key specified by szKeyName already exists in that section. |
szKeyName |
Specifies the name of the key to insert. The value of this parameter will appear to the left of the equal sign in the profile string (szKeyName = szValue). |
szValue |
Specifies the value to assign to the key. The value of this parameter will appear to the right of the equal sign in the profile string (szKeyName = szValue). |
Return Value |
Description |
---|---|
0 |
AddProfString successfully added the specified profile string to the .ini file. |
< 0 |
AddProfString was unable to add the profile string. |
See Also
InstallShield 2009 » InstallScript Language Reference
Note
To call this function in a Basic MSI setup, you must first create a custom action for the entry-point function, execute the custom action in a sequence or as the result of a dialog's control event, and then build the release.
/*-----------------------------------------------------------*\
*
* InstallShield Example Script
*
* Demonstrates the functions AddProfString and GetProfString.
*
* This script adds a profile string to a file; then it
* retrieves and displays the string that was added.
*
* Note: The first time you run this script, it will create a
* file named ISExampl.ini in the root of drive C. You
* can delete that file when you have finished analyzing
* this script.
*
\*-----------------------------------------------------------*/
#define EXAMPLE_INI "C:\\ISExampl.ini"
// The new section, key, and value to add to the file.
#define NEW_SECTION "New Section"
#define NEW_KEY "New Key"
#define NEW_VALUE "Test"
// Include Ifx.h for built-in InstallScript function prototypes.
#include "Ifx.h"
export prototype ExFn_AddProfString(HWND);
function ExFn_AddProfString(hMSI)
STRING svResult;
begin
// Add the profile string to the file.
if (AddProfString (EXAMPLE_INI, NEW_SECTION, NEW_KEY, NEW_VALUE) != 0) then
// Display an error message if the string could not be added.
MessageBox ("AddProfString failed.", SEVERE);
else
// Retrieve the value of a key from the file.
if (GetProfString (EXAMPLE_INI, NEW_SECTION, NEW_KEY, svResult) != 0) then
// Display an error message if the string could not be retrieved.
MessageBox ("GetProfString failed.", SEVERE);
else
// Display the key and its current value.
MessageBox (NEW_KEY + "=" + svResult, INFORMATION);
endif;
endif;
end;