Author: Calvin Smith
http://www.CalvinSmithSoftware.com/codedisk/sneakpeek.htm

The following code will allow a developer to programmatically
detect the path of the Windows or the Windows System directory
without hard-coding.


NOTE: This function, plus some of my others, were featured in
The Visual Basic Programmer's Journal Top 101 Tech Tips Issue.


'We need the following API declarations first...

Declare Function wu_apiGetWindowsDirectory Lib _
     "kernel32" Alias "GetWindowsDirectoryA" (ByVal _
     lpBuffer As String, ByVal nSize As Long) As Long

Declare Function wu_apiGetSystemDirectory Lib "kernel32" Alias _
     "GetSystemDirectoryA" (ByVal lpBuffer As String, ByVal nSize _
     As Long) As Long

Function WinDirs(strDirNameNeeded As String) As String

On Error GoTo WinDirs_Err

' ---------------------------------------------------------------------------------
' Author: Calvin Smith - JobForCalvin@Yahoo.com
' Environment(s): MS Access (32-bit) / Visual Basic (32-bit)
' ---------------------------------------------------------------------------------
'
'   *****************************************
'   * Courtesy code from my CodeDisk© product
'   *****************************************
   '
   ' ----------------------------------------------------------------------------
   ' Purpose: Returns the name of the Windows OR the Windows System directory
   '
   ' Accepts: The passed in string variable strDirNameNeeded$
   '
   ' Returns: The name of the Windows or Windows System directory
   '
   ' Example: strRetVal$ = WinDirs("WindowsDirectory") - OR -
   '              strRetVal$ = WinDirs("WindowsSystemDirectory")
   ' ----------------------------------------------------------------------------
   '

Dim strBuffer As String
Dim iSize As Integer
Dim lResult As Long

iSize% = 256

strBuffer$ = Space$(iSize%)

   Select Case strDirNameNeeded$

     Case "WindowsDirectory"

          lResult& = wu_apiGetWindowsDirectory(strBuffer$, iSize%)

     Case "WindowsSystemDirectory"

          lResult& = wu_apiGetSystemDirectory(strBuffer$, iSize%)

   End Select

   WinDirs$ = Left$(strBuffer$, lResult&)

WinDirs_Exit:
   Exit Function

WinDirs_Err:

   If Err Then
       MsgBox Err.Description
       Resume WinDirs_Exit
   End If

End Function