Как найти каталог Windows

Материал из DRKB

Как найти каталог Windows[править | править код]

function GetWindowsFolder:string;
var
  p: PChar;
begin
  GetMem(p, MAX_PATH);
  Result := '';
  if GetWindowsDirectory(p, MAX_PATH) > 0 then
    Result := string(p);
  FreeMem(p);
end;


Author: Vit (www.delphist.com, www.drkb.ru, www.unihighlighter.com, www.nevzorov.org)
ID: 01659



type
  TForm1 = class(TForm)
  public
    { Public declarations }
    Windir: string;
    WindirP: PChar;
    Res: Cardinal;
  end;

implementation

procedure TForm1.Button1Click(Sender: TObject);
begin
  WinDirP := StrAlloc(MAX_PATH);
  Res := GetWindowsDirectory(WinDirP, MAX_PATH);
  if Res > 0 then
    WinDir := StrPas(WinDirP);
  Label1.Caption := WinDir;
end;


Source: http://delphiworld.narod.ru/
ID: 01660