Private Declare Function GetWindowsDirectory Lib "kernel32" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongPrivate Const MAX_PATH = 260Private Function GetWinDir()
  Dim WinDir As String
  Dim ChrLen As String
  WinDir = Space(MAX_PATH)
  ChrLen = GetWindowsDirectory(WinDir, MAX_PATH)
  If ChrLen > MAX_PATH Then
    ChrLen = GetWindowsDirectory(WinDir, ChrLen)
  End If
  GetWinDir = Left(WinDir, ChrLen)
End FunctionPrivate Sub Form_Load()
  Text1 = GetWinDir()
End Sub