【问题标题】:How to set automaticly DefaultDirName for previous Inno Setup installation?如何为以前的 Inno Setup 安装自动设置 DefaultDirName?
【发布时间】:2011-04-19 17:48:23
【问题描述】:

我之前在 Inno Setup 中的安装 (A) 的 AppID={{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}。

我有另一个具有不同 AppID 的安装 (B),我想将它安装到与安装 (A) 相同的目录中。

如何自动获取 DefaultDirName?我不想使用相同的 AppID,因为当我卸载安装 (B) 并且安装 (A) 保持安装状态时,它会从注册表中删除 AppID 字符串(安装 (A) 字符串)。

你能帮帮我吗?

【问题讨论】:

  • 我想这属于超级用户吧?
  • 您确实应该为同一个应用程序保留相同的 AppID。如果您这样做了,那么 Inno 将为您完成剩下的工作。

标签: inno-setup


【解决方案1】:

你可能需要一些代码来做你想做的事。您还需要找到应用程序 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。
  • 谢谢各位。我明天试试,然后告诉你。
  • 我试过这段代码,但它不起作用 [代码] function GetDefaultDir(def: string): string; var sTemp:字符串; begin //设置一个默认值,以便安装不会失败。 sTemp := ExpandConstant('C:'); //我们需要获取当前的安装目录。 if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\Uninstall\{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}_is1', 'InstallDir', sTemp) then begin //我们在注册表中找到了值所以我们'会用那个。否则我们使用默认结束;结果:= sTemp;结束;
  • 我很抱歉上面的帖子,我不知道如何在这里使用标签。我正在运行 Win7 64 位,AppID 的字符串是这个:HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}_is1
  • 我找到了另一个代码,但它也不起作用vbforums.com/showthread.php?t=533117 [Code] function GetInstallDirectory(S: String) : String; var installDirectory:字符串;开始 if RegQueryStringValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\', '{8ADA0E54-F327-4717-85A9-9DE3F8A6D100}_is1', installDirectory) then //SUCCESS READING VALUE Result := installDirectory else //FAILED读取值结果:= ExpandConstant('C:');结束;
【解决方案2】:

我开发了以下代码,根据AppID查找安装目录。它容纳每个用户的注册表项以及整个机器的注册表项。它已在域上的 Windows 7 Enterprise 和 Virtual PC XP Professional 机器上进行了测试:

[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;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-01-01
    • 2015-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-04
    相关资源
    最近更新 更多