Microsoft KB Archive/240227

= How To Capture the Path to the Windows and System Folders =

Article ID: 240227

Article Last Modified on 6/29/2004

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft Visual FoxPro 3.0b Standard Edition
 * Microsoft Visual FoxPro 5.0 Standard Edition
 * Microsoft Visual FoxPro 5.0a
 * Microsoft Visual FoxPro 6.0 Professional Edition

-



This article was previously published under Q240227



SUMMARY
This article illustrates how to use the GetWindowsDirectory and GetSystemDirectory functions of the WIN32API to capture the paths to the Windows and Windows\System directories.



MORE INFORMATION
Within some applications, it may be necessary to programmatically determine the path to the WINDOWS and/or WINDOWS\SYSTEM directories. By default, Windows 95 and Windows 98 are installed to the WINDOWS directory. Similarly, the default installation directory for Microsoft Windows NT 4.0 is the WINNT directory. While those are default installation paths, users may change the path to which the operating system files are copied.

The Visual FoxPro GETENV function returns the contents of the specified MS-DOS environment variable. Using this function, the path to the Windows directory may be located by passing the function to the WINDIR environmental variable, which Windows sets when it starts. The syntax for returning the path to the Windows directory is =GETENV('windir')

The following code illustrates how to use the GetWindowsDirectory and GetSystemDirectory functions of the WIN32API to return the paths to the Windows and System directories.

The GetWindowsDirectory function returns the path of the Windows directory. Under Windows 95 and Windows 98, the Windows directory would normally be C:\WINDOWS. Using Windows NT 4.0, the Windows directory would usually be C:\WINNT.

The GetSystemDirectory function returns the path of the System directory. With Windows 95 and Windows 98, that would normally be C:\WINDOWS\SYSTEM. Under Windows NT 4.0, the system files would normally be copied to C:\WINNT\SYSTEM32.   Create a program file named GDirs.PRG using the following code: DECLARE INTEGER GetWindowsDirectory IN kernel32.dll ; STRING @WinBuffer, INTEGER WinBuffLen lcWinBuffer = SPACE(MAX_PATH) =GetWindowsDirectory(@lcWinBuffer, MAX_PATH) lcWinBuffer = LEFT(lcWinBuffer, AT(CHR(0), lcWinBuffer) - 1)
 * 1) DEFINE MAX_PATH 260
 * !* Declare the GetWindowsDirectory function from the WIN32API
 * !* Get the path to the windows directory
 * !* Parse the null terminator from the returned string

DECLARE INTEGER GetSystemDirectory IN kernel32.dll ; STRING @SysBuffer, INTEGER SysBufferLen lcSysBuffer = SPACE(MAX_PATH) =GetSystemDirectory(@lcSysBuffer, MAX_PATH) lcSysBuffer = LEFT(lcSysBuffer, AT(CHR(0), lcSysBuffer) - 1)
 * !* Declare the GetSystemDirectory function from the WIN32API
 * !* Get the path to the system directory
 * !* Parse the null terminator from the returned string

? "Windows Directory = " + lcWinBuffer ? "System Directory = " + lcSysBuffer CLEAR DLLS  Run the GDirs.prg file. Note that the path to the Windows and the System directories appear on the screen.

