# WriteProfileString Function

`Declare Function WriteProfileString Lib "kernel32.dll" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long`

WriteProfileString sets a value inside of the WIN.INI file. This function can also be used to set numerical values if they are in string form, for example using "1". If the section or value does not exist, it will be created. Note that, since Windows normally handles the WIN.INI file by iself, care should be taken when writing directly to it. This function if basically a watered-down version of WritePrivateProfileString because, unlike this function, it works with any INI file. The function returns 0 if an error occurs, or a non-zero value if successful.

lpszSection
  The section of WIN.INI to write to.
lpszKeyName
  The name of the value to set.
lpszString
  The string to set as the value.

Example:

    ' Edit the "Wallpaper" setting in the [Desktop] section of WIN.INI
    ' (NOTE: It is best not to directly edit system configuration files like this)
    x = WriteProfileString("Desktop", "Wallpaper", "C:\Windows\Clouds.bmp")

Related Calls: GetProfileString, WritePrivateProfileString
Category: INI Files
Back to the index.