WritePrivateProfileString Function

Declare Function WritePrivateProfileString Lib "kernel32.dll" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long

Platforms: Win 32s, Win 95/98, Win NT

WritePrivateProfileString sets a value inside of an INI file. This function can also be used to set numerical values if they are in string form, for example using "1" to represent the number 1. If the INI file you try to write to does not exist, it will be created. Likewise, if the section or value does not exist, it will also be created. The function returns 0 if an error occurs, or 1 if successful. Note that INI file support is only provided in Windows for backwards compatibility; using the registry to store information is preferred.

lpApplicationName
The section of the INI file to write to.
lpKeyName
The name of the value to set.
lpString
The string to set as the value.
lpFileName
The filename of the INI file to write to.

Example:

' Set the "username" setting in the [Default] section of
' C:\MyProgram\config.ini to "Rimmer".  Also set the "useinfo" setting under the same
' section to 1 (i.e., "1").
Dim retval As Long  ' return value

' Set the string value.
retval = WritePrivateProfileString("Default", "username", "Rimmer", "C:\MyPrograms\config.ini")

' Set the numeric value.
retval = WritePrivateProfileString("Default", "useinfo", "1", "C:\MyPrograms\config.ini")

See Also: GetPrivateProfileString, WriteProfileString
Category: INI Files

Go back to the alphabetical Function listing.
Go back to the Reference section index.


This page is copyright © 2000 Paul Kuliniewicz. Copyright Information.
Go back to the Windows API Guide home page.
E-mail: vbapi@vbapi.com Send Encrypted E-Mail
This page is at http://www.vbapi.com/ref/w/writeprivateprofilestring.html