DOC: GetSystemWindowsDirectory() Is Not Supported in Windows NT 4.0 Terminal Server Edition

Article translations Article translations
Article ID: 281316 - View products that this article applies to.
This article was previously published under Q281316
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page

SUMMARY

Some earlier versions of the Platform SDK documentation for the GetSystemWindowsDirectory() API contains an error indicating that the function is supported in Microsoft Windows NT 4.0 Terminal Server Edition for Service Pack 4 and later. This is not accurate. The GetSystemWindowsDirectory() API is only supported in Microsoft Windows 2000. An attempt to call the ANSI version of this function in Windows NT 4.0 will result in the following error:
Entry Point Not Found

The procedure entry point GetSystemWindowsDirectoryA could not be located in the dynamic link library KERNEL32.dll.
Unicode-based applications will get a similar message for GetSystemWindowsDirectoryW.

MORE INFORMATION

GetSystemWindowsDirectory() is used to retrieve the path of the shared Windows directory on a multi-user system. This has the same effect as calling the GetWindowsDirectory() API on a non-Terminal Server system.

On a system that is running Terminal Server, each user has a unique Windows directory. GetWindowsDirectory() returns this unique directory and therefore cannot be used to retrieve the shared Windows directory. To retrieve the shared Windows directory on Windows NT 4.0 Terminal Server Edition, an application can call GetSystemDirectory() and trim "System32" from the end of the returned path.

Sample Code

The following sample code demonstrates how to retrieve the shared Windows directory for both Windows NT 4.0 and Windows 2000. If the operating system is Windows 2000 or later, this code makes a call to GetSystemWindowsDirectory(). Otherwise, it calls GetSystemDirectory() and then trims the last element from the returned path.
#include <windows.h>
#include <tchar.h>
#include <stdio.h>

typedef UINT (STDMETHODCALLTYPE FAR * PFNGETSYSTEMWINDOWSDIRECTORY) (
   LPTSTR lpBuffer,
   UINT uSize
);

PFNGETSYSTEMWINDOWSDIRECTORY fnGetSystemWindowsDirectory = NULL;

#ifdef UNICODE
#define GETSYSTEMWINDOWSDIRECTORY "GetSystemWindowsDirectoryW"
#else
#define GETSYSTEMWINDOWSDIRECTORY "GetSystemWindowsDirectoryA"
#endif

void main() {

   TCHAR szWindowsDir[MAX_PATH];
   PTCHAR pBackslash;

   // Determine the OS version
   OSVERSIONINFO osvi;
 
   ZeroMemory(&osvi, sizeof(osvi));
   osvi.dwOSVersionInfoSize = sizeof(osvi);

   if(!GetVersionEx(&osvi)) {
      _tprintf(_T("GetVersionEx() failed with error %d\n"), 
            GetLastError());
      return;
   }

   if (osvi.dwMajorVersion >= 5) {
   
      // On Windows 2000 or later, use GetSystemWindowsDirectory()
      fnGetSystemWindowsDirectory =
            (PFNGETSYSTEMWINDOWSDIRECTORY) GetProcAddress( 
            GetModuleHandle(_T("kernel32.dll")),
            GETSYSTEMWINDOWSDIRECTORY);

      fnGetSystemWindowsDirectory(szWindowsDir, MAX_PATH);

   } else {

      // On earlier systems, use GetSystemDirectory()
      GetSystemDirectory(szWindowsDir, MAX_PATH);

      // Locate the last element of the path (the System32 directory)
      pBackslash = _tcsrchr(szWindowsDir, _T('\\'));

      // Truncate the string to exclude the last element
      *pBackslash = _T('\0');
   }

   _tprintf(_T("%s\n"), szWindowsDir);
}
				

Properties

Article ID: 281316 - Last Review: February 28, 2014 - Revision: 4.1
APPLIES TO
  • Microsoft Win32 Application Programming Interface, when used with:
    • Microsoft Windows NT 4.0
Keywords: 
kbnosurvey kbarchive kbapi kbbug kbdocerr kbkernbase kbnofix KB281316

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com