You are currently offline, waiting for your internet to reconnect

How to Write to Windows-Style .INI Files

This article was previously published under Q95720
This article has been archived. It is offered "as is" and will no longer be updated.
SUMMARY
The following examples show how to write specific information to Windows-style .INI files. The first example shows how to write information to theWIN.INI file, and the second example shows how to write information to anyother Windows-style .INI file.
MORE INFORMATION

Example 1

The following code will write to the Load= line in the [Windows] section ofthe WIN.INI file:
   SET LIBRARY TO SYS(2004)+"FOXTOOLS.FLL"   MAPPNAME="WINDOWS"   MKEYNAME="LOAD"   MSETTING="CLOCK.EXE"   MREGISTER=REGFN("WRITEPROFILESTRING","CCC","I")   MCALL=CALLFN(MREGISTER,MAPPNAME,MKEYNAME,MSETTING)				
MAPPNAME points to an application heading in the WIN.INI file. In thiscase, it is pointing to the [Windows] application name.

MKEYNAME points to a key name that appears under the application name. Theabove example points to the Load= line.

MSETTING is the string that contains the value to be assigned to the keyname.

NOTE: The code in Example 1 puts CLOCK.EXE on the Load= line. It does notappend CLOCK.EXE to any existing information for this key name. It simplyreplaces the value. If the Load= line was not present in the [Windows]section of the WIN.INI file, this code would have added it.

MREGISTER is the variable name that defines the function using the RegFnfunction. The sample code above registers the function WriteProfileStringand will write information to the WIN.INI file.

MCALL is used to call the function defined in MREGISTER and pass it theappropriate parameters.

To write to a different section of the WIN.INI, change the value ofMAPPNAME to the appropriate application name. Also, change the MKEYNAMEvalue to the key name that will hold the information, and change theMSETTING value to the setting to store in the selected key name.

NOTE: The application name and key name are not case sensitive.

Example 2

The following code will change the COLOR SCHEMES= line in the [Current]section of the CONTROL.INI file:
   SET LIBRARY TO SYS(2004)+"FOXTOOLS.FLL"   MAPPNAME="CURRENT"   MKEYNAME="COLOR SCHEMES"   MSETTING="FLUORESCENT"   MFILENAME="CONTROL.INI"   MREGISTER=REGFN("WRITEPRIVATEPROFILESTRING","CCCC","I")   MCALL=CALLFN(MREGISTER,MAPPNAME,MKEYNAME,MSETTING,MFILENAME)				
The commands are almost the same as those in Example 1, except that Example2 uses WritePrivateProfileString. This allows you to specify a Windows-style .INI file other than the WIN.INI file. One other difference is theaddition of MFILENAME to specify the .INI file to write to. By default, ifno path is specified, Windows will look in the Windows program directoryfor the .INI file.
VFoxWin FoxWin 2.50
Properties

Article ID: 95720 - Last Review: 02/28/2014 00:25:39 - Revision: 2.1

Microsoft Visual FoxPro 3.0 Standard Edition, Microsoft FoxPro 2.5b, Microsoft FoxPro 2.5a

  • kbnosurvey kbarchive kbcode KB95720
Feedback