delphi获得系统路径的有哪些方法
在Delphi中,可使用以下方法来获得系统路径:
uses
SysUtils;
var
systemPath: string;
begin
systemPath := SysUtils.GetEnvironmentVariable('windir'); // 获得 Windows 系统文件夹路径
// 还是
systemPath := SysUtils.GetEnvironmentVariable('systemroot'); // 获得 Windows 系统根文件夹路径
end;
uses
ShellAPI;
var
systemPath: array[0..MAX_PATH] of Char;
begin
if SHGetSpecialFolderPath(0, systemPath, CSIDL_WINDOWS, False) then // 获得 Windows 系统文件夹路径
ShowMessage(systemPath);
// 还是
if SHGetSpecialFolderPath(0, systemPath, CSIDL_SYSTEM, False) then // 获得 Windows 系统根文件夹路径
ShowMessage(systemPath);
end;
请注意,以上代码示例中的路径常量和函数可能需要根据您的实际需求进行调剂。
TOP