Attribute VB_Name = "WinDir"
Public Declare Function GetWindowsDirectory Lib "kernel32" _
Alias "GetWindowsDirectoryA" _
(ByVal lpBuffer As String, ByVal nSize As Long) As Long

Public Function GetWinDir() As String
Dim WinDir As String ' receives path of Windows directory
Dim SLength As Long ' receives length of the string returned

WinDir = Space(255) ' initialize buffer to receive the string
SLength = GetWindowsDirectory(WinDir, 255) ' read the path of the Windows directory
WinDir = Left(WinDir, SLength) ' extract the returned string from the buffer
GetWinDir = WinDir
End Function

