Click to Rate and Give Feedback
MSDN
MSDN Library
Windows Development
System Services
System Information
 GetSystemDirectory function
GetSystemDirectory function

Applies to: desktop apps only

Retrieves the path of the system directory. The system directory contains system files such as dynamic-link libraries and drivers.

This function is provided primarily for compatibility. Applications should store code in the Program Files folder and persistent data in the Application Data folder in the user's profile. For more information, see ShGetFolderPath.

Syntax

UINT WINAPI GetSystemDirectory(
  __out  LPTSTR lpBuffer,
  __in   UINT uSize
);

Parameters

lpBuffer [out]

A pointer to the buffer to receive the path. This path does not end with a backslash unless the system directory is the root directory. For example, if the system directory is named Windows\System32 on drive C, the path of the system directory retrieved by this function is C:\Windows\System32.

uSize [in]

The maximum size of the buffer, in TCHARs.

Return value

If the function succeeds, the return value is the length, in TCHARs, of the string copied to the buffer, not including the terminating null character. If the length is greater than the size of the buffer, the return value is the size of the buffer required to hold the path, including the terminating null character.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

Applications should not create files in the system directory. If the user is running a shared version of the operating system, the application does not have write access to the system directory.

Examples

For an example, see Getting System Information.

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Winbase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

Unicode and ANSI names

GetSystemDirectoryW (Unicode) and GetSystemDirectoryA (ANSI)

See also

GetCurrentDirectory
GetWindowsDirectory
SetCurrentDirectory
System Information Functions

 

 

Send comments about this topic to Microsoft

Build date: 3/6/2012

Community Content   What is Community Content?
Add new content RSS  Annotations
The documented behaviour of this function on x64 is more or less random      And yet another Dave   |   Edit   |   Show History
Some samples (restricted to only MS sites, beyond that it gets even more confusing), and hopefully I've read these correctly: http://msdn.microsoft.com/en-us/library/bb762584%28VS.85%29.aspx: CSIDL_SYSTEM = %windir%/System32, CSIDL_SYSTEMX86 = %windir%/System32. http://social.technet.microsoft.com/Forums/en/appvgeneralsequencing/thread/c58f7d64-6a23-46f0-998f-0a964c1eff2a: CSIDL_SYSTEM = %windir%/Syswow64. http://msdn.microsoft.com/en-us/library/windows/desktop/ms538044%28v=vs.85%29.aspx: CSIDL_SYSTEM = %windir%/System32, CSIDL_SYSTEMX86 = %windir%/Syswow64. http://social.msdn.microsoft.com/Forums/en-US/vcgeneral/thread/f9a54564-1006-42f9-b4d1-b225f370c60c: GetSystemDirectory() = %windir%/Syswow64. http://msdn.microsoft.com/en-us/library/windows/desktop/dd378457%28v=vs.85%29.aspx: CSIDL_SYSTEM = %windir%/System32, CSIDL_SYSTEMX86 = %windir%/System32 for Win32, %windir%/Syswow64 for Win64. Could we perhaps get some sort of definitive statement on what GetSystemDirectory()/CSIDL_SYSTEM/etc really do (or at least are supposed to do)? I could try it on my current Win7 x64 system but given the random behaviour documented above I wouldn't be sure whether that applies only to that particular machine's setup or can be generalised.
Tags What's this?: Add a tag
Flag as ContentBug
Make sure you null out lpBuffer if the function returns 0      Daniel Martín   |   Edit   |   Show History
If you use the PathAppend API after GetSystemDirectory to compose a path to a system file, your software may be vulnerable to a buffer overrun bug. Don't forget to exit early or null out lpBuffer if GetSystemDirectory returns 0: WCHAR szRundllPath[MAX_PATH]; // Local variable if (0 == GetSystemDirectory(szRundllPath, ARRAYSIZE(szRundllPath))) { szRundllPath[0] = TEXT('\0'); } if (PathAppend(szRundllPath, TEXT("rundll32.exe"))) { ... }
Tags What's this?: Add a tag
Flag as ContentBug
Windows x64 Values      crescens2k   |   Edit   |   Show History

Just to clarify. On Windows x64, this will return the path to your System32 directory regardless of your application being a native x64 application or if it is a x86 application running under WoW64.

What Windows relies on to get this working in WoW64 is the file system redirection. This makes it so that an x86 application will redirect the System32 directory to Syswow64 silently without anybody having to know or care. So even on x64 Windows, this directory is System32.
You could always write a simple test application yourself to check it out since calling this is easy.

Tags What's this?: Add a tag
Flag as ContentBug
Windows7 x64 is....      SLinker   |   Edit   |   Show History
value is Windows\sysWOW64
Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2012 Microsoft. All rights reserved. Terms of Use | Trademarks | Privacy Statement
Page view tracker