//获取软件的安装路径
function GetPath(Param: String): String;
var
sInstallPath: String;
len: Longint;
begin
sInstallPath := '';
if RegValueExists(HKLM, 'SOFTWARE\Microsoft\DrWatson', 'LogFilePath') then//从注册表中获取路径
begin
RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\DrWatson', 'LogFilePath', sInstallPath)
len := Length(sInstallPath) //获取路径字符串的长度
sInstallPath := Copy(sInstallPath,1,len-4)//去掉路径字符串的后4个字符
Insert('bin\', sInstallPath, len-3);//给路径最后添加字符串'bin\'
end
Result := sInstallPath;
end;
打补定时,获取安装盘的安装路径,2钟方法。
1.从注册表中获取
前提是安装盘的路径在注册表中记录。
例如:
//获取软件的安装路径
function GetPath(Param: String): String;
var
sInstallPath: String;
len: Longint;
begin
sInstallPath := '';
if RegValueExists(HKLM, 'SOFTWARE\Microsoft\DrWatson', 'LogFilePath') then//从注册表中获取路径
begin
RegQueryStringValue(HKLM, 'SOFTWARE\Microsoft\DrWatson', 'LogFilePath', sInstallPath)
end
Result := sInstallPath;
end;
2.从安装包的ini文件中获取,该ini文件记录了安装盘的安装路径
例如:
该ini文件路径在C盘根目录,名字为install.ini
内容为:[common]字段的installpath变量记录了安装盘路径d:\。
sinstallpath := GetIniString('common','installpath','',ExpandConstant('{win}\install.ini'))