AllAPI Network - The KPD-Team

Allapi Network

 API List

API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
This Site
 Search Engine
 Contact Form

Donate to

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.


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


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)
    GetWinPath = ""
End If
End Function


An example of how to use this function:

Call MsgBox("The Windows directory is " & GetWinPath, _



Copyright © 1998-2007, The Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at