Microsoft KB Archive/95720

= How to Write to Windows-Style .INI Files =

Article ID: 95720

Article Last Modified on 11/17/2003

-

APPLIES TO


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

-



This article was previously published under Q95720



SUMMARY
The following examples show how to write specific information to Windows- style .INI files. The first example shows how to write information to the WIN.INI file, and the second example shows how to write information to any other Windows-style .INI file.



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

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

MSETTING is the string that contains the value to be assigned to the key name.

NOTE: The code in Example 1 puts CLOCK.EXE on the Load= line. It does not append CLOCK.EXE to any existing information for this key name. It simply replaces 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 RegFn function. The sample code above registers the function WriteProfileString and will write information to the WIN.INI file.

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

To write to a different section of the WIN.INI, change the value of MAPPNAME to the appropriate application name. Also, change the MKEYNAME value to the key name that will hold the information, and change the MSETTING 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)+&quot;FOXTOOLS.FLL&quot; MAPPNAME=&quot;CURRENT&quot; MKEYNAME=&quot;COLOR SCHEMES&quot; MSETTING=&quot;FLUORESCENT&quot; MFILENAME=&quot;CONTROL.INI&quot; MREGISTER=REGFN(&quot;WRITEPRIVATEPROFILESTRING&quot;,&quot;CCCC&quot;,&quot;I&quot;) MCALL=CALLFN(MREGISTER,MAPPNAME,MKEYNAME,MSETTING,MFILENAME) The commands are almost the same as those in Example 1, except that Example 2 uses WritePrivateProfileString. This allows you to specify a Windows- style .INI file other than the WIN.INI file. One other difference is the addition of MFILENAME to specify the .INI file to write to. By default, if no path is specified, Windows will look in the Windows program directory for the .INI file.

Additional query words: VFoxWin FoxWin 2.50

Keywords: kbcode KB95720

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.