我之前在Inno Setup中的安裝(A)有AppID = {{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}。如何爲以前的Inno Setup安裝自動設置DefaultDirName?
我有另一個安裝(B)與不同的AppID,我想安裝到安裝(A)相同的目錄中。
如何自動獲得DefaultDirName?我不想使用相同的AppID,因爲當我卸載安裝(B)並且安裝(A)保持安裝時,它將從註冊表(安裝(A)字符串)中刪除AppID字符串。
你能幫助我嗎?
我之前在Inno Setup中的安裝(A)有AppID = {{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}。如何爲以前的Inno Setup安裝自動設置DefaultDirName?
我有另一個安裝(B)與不同的AppID,我想安裝到安裝(A)相同的目錄中。
如何自動獲得DefaultDirName?我不想使用相同的AppID,因爲當我卸載安裝(B)並且安裝(A)保持安裝時,它將從註冊表(安裝(A)字符串)中刪除AppID字符串。
你能幫助我嗎?
你可能需要一些代碼來做你想做的。您還需要一種方法來發現應用A的安裝目錄下面是我用
[Setup]
DefaultDirName={code:GetDefaultDir}
[Code]
function GetDefaultDir(def: string): string;
var
sTemp : string;
begin
//Set a defualt value so that the install doesn't fail.
sTemp := ExpandConstant('{pf}') + '\MyCompany\MyAppA';
//We need to get the current install directory.
if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\MyCompany\Products\MyAppNameA',
'InstallDir', sTemp) then
begin
//We found the value in the registry so we'll use that. Otherwise we use the default
end;
Result := sTemp;
end;
這隻有在以前的設置記錄了這樣的密鑰時纔有效。如果沒有,可以查詢以前安裝的AppID的Inno Setup:App Path值。關鍵是「HKLM \ Software \ Microsoft \ Windows \ CurrentVersion \ Uninstall \'+ AppID +'_ is1''。沒有太大的區別,所以+1。 – 2011-04-19 21:05:47
謝謝,夥計們。我明天會試一下,讓你知道。 – Jiri 2011-04-19 21:45:17
我試過這段代碼,它不起作用 [code] function GetDefaultDir(def:string):string; var sTemp:string; 開始 //設置一個默認值,以便安裝不會失敗。 sTemp:= ExpandConstant('C:'); //我們需要獲取當前的安裝目錄。 如果RegQueryStringValue(HKEY_LOCAL_MACHINE, '軟件\微軟\的Windows \ CurrentVersion \卸載\ {8ADA0E54-F327-4717-85A9-9DE3F8A6D100} _is1', 'INSTALLDIR',STEMP)然後 開始 //我們發現價值註冊表,所以我們將使用它。否則我們使用默認的 結束; 結果:= sTemp; 結束; – Jiri 2011-04-20 08:16:08
我制定了以下的代碼基礎上找到的AppID安裝目錄中的一些代碼。它適用於每個用戶的註冊表項以及整個機器的註冊表項。它已經在域上和虛擬PC XP Professional機器上的Windows 7 Enterprise上進行了測試:
[code]
const
PreviousAppID = '8ADA0E54-F327-4717-85A9-9DE3F8A6D100';
AppFolder = 'SomeFolder';
UninstallPath = 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{'
+ PreviousAppID + '}_is1';
// Some posts have 'InstallDir', but I have never observed that
InstallKey = 'InstallLocation';
function GetDefaultDir(Param: String) : String;
var
UserSIDs: TArrayOfString;
I: Integer;
begin
// Check if the current user installed it
if RegQueryStringValue(HKEY_CURRENT_USER, UninstallPath,
InstallKey, Result) then
// Current user didn't install it. Did someone else?
else if RegGetSubkeyNames(HKEY_USERS, '', UserSIDs) then begin
for I := 0 to GetArrayLength(UserSIDs) - 1 do begin
if RegQueryStringValue(HKEY_USERS, UserSIDs[I] + '\' + UninstallPath,
InstallKey, Result) then break;
end;
end;
// Not installed per-user
if Result = '' then begin
// What about installed for the machine?
if RegQueryStringValue(HKEY_LOCAL_MACHINE, UninstallPath,
InstallKey, Result) then
// Doesn't appear to be installed, as admin default to Program Files
else if IsAdminLoggedOn() then begin
Result := ExpandConstant('{pf}\') + AppFolder;
// As non-admin, default to Local Application Data
end else begin
Result := ExpandConstant('{localappdata}\') + AppFolder;
end;
end;
end;
所有在Windows 10中都很好。謝謝! :) – 2018-01-20 14:26:58
我認爲這屬於超級用戶,是吧? – Bastardo 2011-04-19 17:53:19
你確實應該爲同一個應用程序保留相同的AppID。如果你這樣做,Inno會爲你做剩下的事情。 – Deanna 2012-10-12 16:21:12