Microsoft KB Archive/109733

From BetaArchive Wiki
Knowledge Base


ACC: How to Find the Windows and System Paths

Article ID: 109733

Article Last Modified on 5/6/2003



APPLIES TO

  • Microsoft Access 1.0 Standard Edition
  • Microsoft Access 1.1 Standard Edition
  • Microsoft Access 2.0 Standard Edition



This article was previously published under Q109733

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article describes how to use the GetWindowsDirectory() and GetSystemDirectory() Windows API functions to return the Windows and Windows System directory paths.

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x, or the "Building Applications" manual, Chapter 3, "Introducing Access Basic," in version 2.0.

MORE INFORMATION

The following example demonstrates how to use the GetWindowsDirectory() and GetSystemDirectory() Windows API functions:

  1. Create a new module with the sample code below.

    NOTE: You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code.

    NOTE: In the following sample code, an underscore (_) is used as a line-continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

          '**********************************
          'Declarations section of the module
          '**********************************
          Option Compare Database
          Option Explicit
    
          Declare Function GetWindowsDirectory% Lib "Kernel" (ByVal lpbuffer _
             As String, ByVal nsize As Integer)
          Declare Function GetSystemDirectory% Lib "Kernel" (ByVal lpbuffer _
             As String, ByVal nsize As Integer)
    
          'Returns the path to the Windows directory as a string.
          Function GetWinDir () As String
             Dim lpbuffer As String * 144
             Dim Length%
    
             Length% = GetWindowsDirectory(lpbuffer, Len(lpbuffer))
             GetWinDir = Left(lpbuffer, Length%)
          End Function
    
          'Returns the path to the Windows System directory as a string.
          Function GetSysDir () As String
             Dim lpbuffer As String * 144
             Dim Length%
    
             Length% = GetSystemDirectory(lpbuffer, Len(lpbuffer))
             GetSysDir = Left(lpbuffer, Length%)
          End Function
                            
  2. From the View menu, choose Immediate Window. Type the following in the Immediate window, and then press ENTER:

     ? GetWinDir()

    The Windows directory path will be returned.
  3. Type the following in the Immediate window, and then press ENTER:

     ? GetSysDir()

    The Windows System directory path will be returned.



Additional query words: path system windows api ab

Keywords: kbhowto kbprogramming KB109733