//擷取軟體的安裝路徑
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'))