正如你發現自己,邏輯是硬編碼的。你無法真正控制。
最接近你可以得到的是通過使用無證件(不贊成)PrivilegesRequired=none
。
有了這個值(與安裝,自動檢測的在Windows幫助):
這不完全是你想要的,但我認爲你不能接近。
你當然也可以複製(移動)由代碼HKCU
和HKLM
自己的註冊表項:
function MoveHKCUUninstallKeyToHKLM: Boolean;
var
UninstallKey: string;
AppId: string;
I: Integer;
ValueNames: TArrayOfString;
ValueName: string;
ValueStr: string;
ValueDWord: Cardinal;
begin
if '{#emit SetupSetting("AppId")}' <> '' then
begin
AppId := '{#emit SetupSetting("AppId")}';
end
else
begin
AppId := '{#emit SetupSetting("AppName")}';
end;
Result := False;
if AppId = '' then
begin
Log('Cannot identify AppId');
end
else
begin
UninstallKey :=
'Software\Microsoft\Windows\CurrentVersion\Uninstall\' + AppId + '_is1';
Log(Format(
'AppId identified as "%s", using uninstall key "%s"', [AppId, UninstallKey]));
if not RegKeyExists(HKEY_CURRENT_USER, UninstallKey) then
begin
Log('HKCU uninstall key not found');
end
else
if RegKeyExists(HKEY_LOCAL_MACHINE, UninstallKey) then
begin
Log('HKLM uninstall key exists already');
end
else
begin
Log('HKCU uninstall key found and HKLM key not exists yet');
if not RegGetValueNames(HKEY_CURRENT_USER, UninstallKey, ValueNames) then
begin
Log('Cannot list uninstall key values');
end
else
begin
I := 0;
Result := True;
while (I < GetArrayLength(ValueNames)) and Result do
begin
ValueName := ValueNames[I];
if RegQueryStringValue(HKEY_CURRENT_USER, UninstallKey, ValueName, ValueStr) then
begin
if not RegWriteStringValue(
HKEY_LOCAL_MACHINE, UninstallKey, ValueName, ValueStr) then
begin
Log(Format('Error moving "%s" string value', [ValueName]));
Result := False;
end
else
begin
Log(Format('Moved "%s" string value', [ValueName]));
end;
end
else
if RegQueryDWordValue(
HKEY_CURRENT_USER, UninstallKey, ValueName, ValueDWord) then
begin
if not RegWriteDWordValue(
HKEY_LOCAL_MACHINE, UninstallKey, ValueName, ValueDWord) then
begin
Log(Format('Error moving "%s" dword value', [ValueName]));
Result := False;
end
else
begin
Log(Format('Moved "%s" dword value', [ValueName]));
end;
end
else
begin
{ All uninstall values written by Inno Setup are either string or dword }
Log(Format('Value "%s" is neither string nor dword', [ValueName]));
Result := False;
end;
Inc(I);
end;
if Result then
begin
if not RegDeleteKeyIncludingSubkeys(HKEY_CURRENT_USER, UninstallKey) then
begin
Log('Error removing HKCU uninstall key');
Result := False;
end
else
begin
Log('Removed HKCU uninstall key');
end;
end;
if not Result then
begin
if not RegDeleteKeyIncludingSubkeys(HKEY_CURRENT_USER, UninstallKey) then
begin
Log('Failed to move uninstall key to HKLM, ' +
'and also failed to rollback the changes');
end
else
begin
Log('Failed to move uninstall key to HKLM, rolled back the changes');
end;
end;
end;
end;
end;
end;
procedure CurStepChanged(CurStep: TSetupStep);
begin
if CurStep = ssPostInstall then
begin
Log('Post install');
MoveHKCUUninstallKeyToHKLM;
end;
end;
你當然是對的。我想我必須自己重新執行註冊表編寫工作,我沒有想過簡單地將它們複製到正確的位置。感謝您指出我正確的方向,並看到我的答案,我是如何做到的! – caesay
查看我編輯的原生Inno Setup解決方案的答案。 –
我沒有測試,但看起來不錯。我已經將註冊表內容與我的本地解決方案集成在一起,並針對安裝的應用程序是x64還是x86進行了編碼檢測,將鍵放入正確的視圖中(我的解決方案也忽略了此問題)。無論如何,謝謝你!這兩個答案對於將來找到這個問題的任何人都是有價值的。 – caesay