How can I retrieve the path to the Windows directory?
If your project uses ini files, the best place to save them is in the Windows directory. This tip demonstrates how to go about finding the path to the Windows directory.
Declarations
You must copy this code into the declarations section of the project.
Public Const MAX_PATH = 260 Declare Function GetWindowsDirectory Lib "kernel32" Alias _ "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal _ nSize As Long) As Long
Code
Public Function GetWinPath()
Dim strFolder As String
Dim lngResult As Long
strFolder = String(MAX_PATH, 0)
lngResult = GetWindowsDirectory(strFolder, MAX_PATH)
If lngResult <> 0 Then
GetWinPath = Left(strFolder, InStr(strFolder, _
Chr(0)) - 1)
Else
GetWinPath = ""
End If
End Function
Use
An example of how to use this function:
Call MsgBox("The Windows directory is " & GetWinPath, _
vbInformation)