delphi获取Windows目录|GetSystemDirectory函数
获取Windows 目录
要获取Windows 目录的位置可以调用Win32 的GetWindowsDirectory() 。该函数类似于GetSystemDirectory(),其返回值的含义也与GetSystemDirectory()相同。该函数的用法如下:
procedure TForm1.Button1Click(Sender: TObject);
var
MyWinPath:String;
begin
SetLength(MyWinPath,144);
if GetWindowsDirectory(PChar(MyWinPath),144)<>0 then
begin
SetLength(MyWinPath,Length(PChar(MyWinPath)));
Edit1.Text:=MyWinPath;
end
else
RaiseLastWin32Error;
end;
如果函数调用成功,GetWindowsDirectory()返回目录路径的长度(整数值),否则返回0,表明有错误产生。这时可以调用RaiseLastWin32Error()来分析产生错误的原因。