Home > System > How to Get the Windows System Directory

How to Get the Windows System Directory

December 15th, 1999 m3Rlin Leave a comment Go to comments

To found out the name of the Windows directory it’s best to use the Windows API GetSystemDirectory() function.

Here’s the Delphi implementation:

uses Windows;
...
function GetSystemDir: string;
const
(* The length of the directory buffer. Usually 64 or even 16 is enough :-)
**
** Must be DWORD type.
*)
  dwLength: DWORD = 255;
var
  psSysDir: PChar;
begin
  GetMem(psSysDir, dwLength);
  GetSystemDirectory(psSysDir, dwLength);
  Result := string(psSysDir);
  FreeMem(psSysDir, dwLength);
end;
  1. No comments yet.