How to Use WordBasic to Return Values from Win.ini or Registry

ID: Q86470


The information in this article applies to:
  • Microsoft Word for Windows, versions 1.0, 1.1, 1.1a, 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, version 7.0
  • Microsoft Word for Windows NT, version 6.0


SUMMARY

Using the Microsoft WordBasic GetProfileString and GetPrivateProfileString functions, you can extract information from the Windows Win.ini file if you are using Windows 3.x or the Registry if you are using Word 7.0.

Below are macros that demonstrate the use of the GetProfileString and GetPrivateProfileString functions.

WARNING: ANY USE BY YOU OF THE CODE PROVIDED IN THIS ARTICLE IS AT YOUR OWN RISK. Microsoft provides this macro code "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Word 7.0 for Windows 95 and Word for Windows NT

In Windows 95 and Windows NT, settings are stored in the Registry. You can use SetProfileString and GetProfileString$() to set and return settings from a text file with the name Win.ini (see Word version 6.x macro below), but neither Windows 95, Windows NT, nor Word 7.0 uses these settings. To access values in the Registry from within WordBasic, you need to use the GetPrivateProfileString$() function.

In the following macro, the program directory path for Word 7.0 in the Windows registry is retrieved and stored in the proofdir$ variable. Note: For Word for Windows NT, substitute 6.0 for 7.0 in the registry key for GetPrivateProfileString$() shown below.

Sub MAIN
progdir$ =
GetPrivateProfileString$("HKEY_CURRENT_USER\Software\Microsoft\Word\7.0\options", "Programdir", "")
MsgBox progdir$
End Sub 

Word 6.x for Windows

In the following macro, the proof path under the [MSAPPS] heading in the Win.ini file is retrieved and stored in the A$ variable.

 Sub MAIN
 A$ = GetProfileString$("MSAPPS", "PROOF")
 Msgbox "Proof directory is " + A$
 End Sub 

Word 2.x for Windows

If the DOC-path statement is not present in the [Microsoft Word 2.0] section of your Win.ini file, a dialog box indicates that the default directory has not been set.

 Sub MAIN
 A$ = GetProfileString$("Microsoft Word 2.0", "DOC-Path")
 If A$ = "" Then
  MsgBox "Default Directory is not set"
 Else
  MsgBox "Default Directory is " + A$
 End If
 End Sub 

Word 1.x for Windows


 Sub MAIN
 A$ = GetProfileString$("Microsoft Word", "DOC-Path")
 If A$ = "" Then
  MsgBox "Template Directory is not set"
 Else
  MsgBox "Template Directory is " + A$
 End If
 End Sub 


MORE INFORMATION

If you are using Word 7.0 and the GetPrivateProfileString$() function in Windows 95 and Windows NT to return a setting in the Registry, you must specify the complete path to the key, including the root (for example, "HKEY_CURRENT_USER\software\Microsoft\Word\7.0\Options").

Word 6.0 for Windows stores most of the Word-specific settings in the Winword6.ini file. This file is located in your Windows folder. Using the GetPrivateProfileString statement, you can read information from the Winword6.ini file.

If you are using Word 2.x for Windows, you can use the Microsoft Windows GetPrivateProfileString command in a WordBasic macro to read information from an .ini file other than the Win.ini file. For more information, query on the following words in the Microsoft Knowledge Base:

private and text and file


REFERENCES

"Using WordBasic," by WexTech Systems and Microsoft, page 228
"Microsoft Word Developers Kit", by MS Press

Additional query words: 1.10a 2.0 6.0 7.0 winword2 winword word6 word7 word95 registry ntword wordnt

Keywords :
Version : WINDOWS:1.0,1.1,1.1a,2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0; winnt:6.0
Platform : WINDOWS winnt
Issue type :


Last Reviewed: September 30, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.