ACC: How to Find the Windows and System Paths

Last reviewed: November 19, 1997
Article ID: Q109733
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0

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 : kbprg
Version : 1.0 1.1 2.0
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 19, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.