- W -


WritePrivateProfileString Function

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

WritePrivateProfileString sets a value inside of any INI file. Although the function name seems to say otherwise, this works with integer values as well as strings. If the INI file you try to write to does not exist, it will be created. If the section or value you try to set does not exist, it will also be created. It is safe to ignore the value returned.
lpApplicationNameThe section of the INI file to write to. This is the name inside of brackets, but do not include the brackets in the parameter.
lpKeyNameThe name of the value to set. This is the name on the left side of the = sign.
lpStringThe string or integer value to write. This is what will appear on the right side of the = sign.
lpFileNameThe filename of the INI file to write to.
Example:
  'Edit the "scrnsave.exe" setting in the [boot] section of SYSTEM.INI
  '(This assumes your Windows directory is C:\Windows)
  '(NOTE: this is an example. It is best not to edit system files like this)
  x = WritePrivateProfileString("boot", "scrnsave.exe", "C:\WINDOWS\SYSTEM\SCROLL~1.SCR", "c:\windows\system.ini")
  Form1.Print "Screen saver set to Scrolling Marquee."


Related Calls: GetPrivateProfileString, WriteProfileString
Category: INI Files
Back to the index.


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 string value inside of the WIN.INI file. Although the function name seems to say otherwise, you can write numbers to the file if you encase them in quotes. If the section or value you try to set does not exist, it will also be created. It is safe to ignore the value returned. This is basically a watered-down version of WritePrivateProfileString because, unlike that, WriteProfileString only works with WIN.INI.
lpszSectionThe section of WIN.INI to write to. This is the name inside of brackets, but do not include the brackets in the parameter.
lpszKeyNameThe name of the value to set. This is the name on the left side of the = sign.
lpszStringThe string or integer value to write. This is what will appear on the right side of the = sign.
Example:
  'Edit the "Wallpaper" setting in the [Desktop] section of WIN.INI
  '(NOTE: this is an example. It is best not to edit system files like this)
  x = WriteProfileString("Desktop", "Wallpaper", "C:\WINDOWS\CLOUDS.BMP")
  Form1.Print "Wallpaper set to CLOUDS.BMP"


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


Home
Paul Kuliniewicz
E-mail: Borg953@aol.com
All material presented on these pages is Copyright © Paul Kuliniewicz, except for other copyrighted material.
http://members.aol.com/Borg953/api/w.html