The most well-known .INI file is the WIN.INI file. Windows, and certain applications, keep saved settings in this file. We'll talk more about the WIN.INI file later.
On Windows NT systems, most sections of the WIN.INI (and other system .INI files) are mapped into the registry. That is to say, Windows intercepts certain requests to access the WIN.INI and, instead, accesses the registry. To determine which sections are mapped in this way, refer to the registry key:
GetPrivateProfileInt |
| Description |
Retrieves an integer value from any .INI file |
| Declaration |
Declare Function GetPrivateProfileInt Lib "kernel32" _
Alias "GetPrivateProfileIntA" _
(ByVal sSectionName As String, _
ByVal sKeyName As String, _
ByVal lDefault As Long, _
ByVal sFileName As String) As Long |
| Parameters |
sSectionName |
The name of the section to search. |
| sKeyName |
The name of the key to retrieve. |
| lDefault |
The value to return if the desired key does not exist. |
| sFileName |
The filename of the .INI file to search. If a pathname is not supplied, it will be assumed that the file exists in the Windows directory. |
| Return Value |
The value found or the default value supplied. For values that are not valid integers, this function will return as much of the value as can be interpreted as a valid integer. For example, if the entry where "abc=123xyz", the value of 123 would be returned.
If the value is prefixed with "x" or "0x" then the value is converted as a hexadecimal number. For example, if the entry where "abc=0x1a", the value of &H1A, or 26, would be returned. |
| |
GetPrivateProfileSection |
| Description |
Retrieves data for an entire section of any .INI file |
| Declaration |
Declare Function GetPrivateProfileSection Lib "kernel32" _
Alias "GetPrivateProfileSectionA" _
(ByVal sSectionName As String, _
ByVal sReturnedString As String, _
ByVal lSize As Long, _
ByVal sFileName As String) As Long |
| Parameters |
sSectionName |
The name of the section to search. |
| sReturnedString |
The string variable that will contain the list of entries for the specified section. The string must be pre-sized to at least lSize bytes. |
| lSize |
The maximum # of characters to load into sReturnedString. |
| sFileName |
The filename of the .INI file to search. If a pathname is not supplied, it will be assumed that the file exists in the Windows directory. |
| Return Value |
The # of characters loaded into sReturnedString. If the return value is lSize-2, sReturnedString is not large enough to hold the entire value. |
| |
GetPrivateProfileString |
| Description |
Retrieves a string value from any .INI file |
| Declaration |
Declare Function GetPrivateProfileString Lib "kernel32" _
Alias "GetPrivateProfileStringA" _
(ByVal sSectionName As String, _
ByVal sKeyName As String, _
ByVal sDefault As String, _
ByVal sReturnedString As String, _
ByVal lSize As Long, _
ByVal sFileName As String) As Long |
| Parameters |
sSectionName |
The name of the section to search. If vbNullString is passed, a list of all the sections in the .INI file will be returned in sReturnedString. |
| sKeyName |
The name of the key to retrieve. If vbNullString is passed, a list of all the key names in the section will be returned in sReturnedString. |
| sDefault |
The value to return if the desired key does not exist. |
| sReturnedString |
The string variable that will contain the desired value. The string must be pre-sized to at least lSize bytes. |
| lSize |
The maximum # of characters to load into sReturnedString. |
| sFileName |
The filename of the .INI file to search. If a pathname is not supplied, it will be assumed that the file exists in the Windows directory. |
| Return Value |
The # of characters loaded into sReturnedString, not counting the terminating NULL character. If the return value is lSize-1, sReturnedString is not large enough to hold the entire value. |
| |
GetProfileInt |
| Description |
Retrieves an integer value from the WIN.INI file |
| Declaration |
Declare Function GetProfileInt Lib "kernel32" _
Alias "GetProfileIntA" _
(ByVal sSectionName As String, _
ByVal sKeyName As String, _
ByVal lDefault As Long) As Long |
| Parameters |
sSectionName |
The name of the section to search. |
| sKeyName |
The name of the key to retrieve. |
| lDefault |
The value to return if the desired key does not exist. |
| Return Value |
The value found or the default value supplied. For values that are not valid integers, this function will return as much of the value as can be interpreted as a valid integer. For example, if the entry where "abc=123xyz", the value of 123 would be returned.
If the value is prefixed with "x" or "0x" then the value is converted as a hexadecimal number. For example, if the entry where "abc=0x1a", the value of &H1A, or 26, would be returned. |
| |
GetProfileSection |
| Description |
Retrieves data for an entire section of the WIN.INI file |
| Declaration |
Declare Function GetProfileSection Lib "kernel32" _
Alias "GetProfileSectionA" _
(ByVal sSectionName As String, _
ByVal sReturnedString As String, _
ByVal lSize As Long) As Long |
| Parameters |
sSectionName |
The name of the section to search. |
| sReturnedString |
The string variable that will contain the list of entries for the specified section. The string must be pre-sized to at least lSize bytes. |
| lSize |
The maximum # of characters to load into sReturnedString. |
| Return Value |
The # of characters loaded into sReturnedString. If the return value is lSize-2, sReturnedString is not large enough to hold the entire value. |
| |
GetProfileString |
| Description |
Retrieves a string value from the WIN.INI file |
| Declaration |
Declare Function GetProfileString Lib "kernel32" _
Alias "GetProfileStringA" _
(ByVal sSectionName As String, _
ByVal sKeyName As String, _
ByVal sDefault As String, _
ByVal sReturnedString As String, _
ByVal lSize As Long) As Long |
| Parameters |
sSectionName |
The name of the section to search. If vbNullString is passed, a list of all the sections in the WIN.INI file will be returned in sReturnedString. |
| sKeyName |
The name of the key to retrieve. If vbNullString is passed, a list of all the key names in the section will be returned in sReturnedString. |
| sReturnedString |
The string variable that will contain the desired value. The string must be pre-sized to at least lSize bytes. |
| lSize |
The maximum # of characters to load into sReturnedString. |
| Return Value |
The # of characters loaded into sReturnedString, not counting the terminating NULL character. If the return value is lSize-1, sReturnedString is not large enough to hold the entire value. |
| |
WritePrivateProfileSection |
| Description |
Writes data to an entire section of any .INI file |
| Declaration |
Declare Function WritePrivateProfileSection Lib "kernel32" _
Alias "WritePrivateProfileSectionA" _
(ByVal sSectionName As String, _
ByVal sString As String, _
ByVal sFileName As String) As Long |
| Parameters |
sSectionName |
The name of the section to be replaced. Any existing entries in the section will be replaced. If the section does not exist, a new one will be appended to the file. |
| sString |
The list of entries to write. The entries in the list must be delimited by a NULL character; the list must be terminated by two NULL characters. |
| sFileName |
The name of the .INI file to be written. If a pathname is not supplied, it will be assumed that the file is located in the Windows directory. If the file does not exist, a new one will be created. |
| Return Value |
Returns non-zero on success; zero on failure. |
| |
WritePrivateProfileString |
| Description |
Writes a string value to any .INI file |
| Declaration |
Declare Function WritePrivateProfileString Lib "kernel32" _
Alias "WritePrivateProfileStringA" _
(ByVal sSectionName As String, _
ByVal sKeyName As String, _
ByVal sString As String, _
ByVal sFileName As String) As Long |
| Parameters |
sSectionName |
The name of the section to be written. If the section does not exist, a new one will be appended to the file. |
| sKeyName |
The name of the key to be replaced. Any existing value for this key will be replaced. If the key does not exist, a new entry will be appended to the section. If vbNullString is passed, the entire section, including the section header, will be deleted from the .INI file. |
| sString |
The new value to be assigned. If vbNullString is passed, the key will be deleted from the section. |
| sFileName |
The name of the .INI file to be written. If a pathname is not supplied, it will be assumed that the file is located in the Windows directory. If the file does not exist, a new one will be created. |
| Return Value |
Returns non-zero on success; zero on failure. |
| |
WriteProfileSection |
| Description |
Writes data to an entire section of the WIN.INI file |
| Declaration |
Declare Function WriteProfileSection Lib "kernel32" _
Alias "WriteProfileSectionA" _
(ByVal sSectionName As String, _
ByVal sString As String) As Long |
| Parameters |
sSectionName |
The name of the section to be replaced. Any existing entries in the section will be replaced. If the section does not exist, a new one will be appended to the file. |
| sString |
The list of entries to write. The entries in the list must be delimited by a NULL character; the list must be terminated by two NULL characters. |
| Return Value |
Returns non-zero on success; zero on failure. |
| |
WriteProfileString |
| Description |
Writes a string value to the WIN.INI file |
| Declaration |
Declare Function WriteProfileString Lib "kernel32" _
Alias "WriteProfileStringA" _
(ByVal sSectionName As String, _
ByVal sKeyName As String, _
ByVal sString As String) As Long |
| Parameters |
sSectionName |
The name of the section to be written. If the section does not exist, a new one will be appended to the file. |
| sKeyName |
The name of the key to be replaced. Any existing value for this key will be replaced. If the key does not exist, a new entry will be appended to the section. If vbNullString is passed, the entire section, including the section header, will be deleted from the WIN.INI file. |
| sString |
The new value to be assigned. If vbNullString is passed, the key will be deleted from the section. |
| Return Value |
Returns non-zero on success; zero on failure. |