Use a part of a registry key/value in the Inno Setup script

别等时光非礼了梦想. 提交于 2020-01-02 10:18:50

问题


I have a need to retrieve a path to be used for some stuffs in the installer according an other application previously installed on the system.

This previous application hosts a service and only provides one registry key/value hosting this information: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\APPLICATION hosting the value ImagePath which Data is "E:\TestingDir\Filename.exe".

I need a way to only extract the installation path (E:\TestingDir) without the Filename.exe file.

Any suggestion? thanks a lot


回答1:


You can achieve this using a scripted constant.

You define a function that produces the value you need:

[Code]

function GetServiceInstallationPath(Param: string): string;
var
  Value: string;
begin
  if RegQueryStringValue(
       HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Services\APPLICATION',
       'ImagePath', Value) then
  begin
    Result := ExtractFileDir(Value);
  end
    else
  begin
    Result := { Some fallback value }
  end;
end;

And then you refer to it using {code:GetServiceInstallationPath} where you need it (like in the [Run] section).

For example:

[Run]
Filename: "{code:GetServiceIntallationPath}\SomeApp.exe"

Actually, you probably want to retrieve the value in InitializeSetup already, and cache the value in a global variable for use in the scripted constant. And abort the installation (by returning False from InitializeSetup), in case the other application is not installed (= the registry key does not exist).

[Code]

var
  ServiceInstallationPath: string;

function InitializeSetup(): Boolean;
var
  Value: string;
begin
  if RegQueryStringValue(
       HKEY_LOCAL_MACHINE, 'SYSTEM\CurrentControlSet\Services\APPLICATION',
       'ImagePath', Value) then
  begin
    ServiceInstallationPath := ExtractFileDir(Value);
    Log(Format('APPLICATION installed to %s', [ServiceInstallationPath]));
    Result := True;
  end
    else
  begin
    MsgBox('APPLICATION not installed, aborting installation', mbError, MB_OK);
    Result := False;
  end;
end;

function GetServiceInstallationPath(Param: string): string;
begin
  Result := ServiceInstallationPath;
end;

See also a similar question: Using global string script variable in Run section in Inno Setup.




回答2:


Solved this way: [code] var ServiceInstallationPath: string;

function MyProgCheck(): Boolean;
var
  Value: string;
begin
  if RegQueryStringValue(
       HKEY_LOCAL_MACHINE, 'SYSTEM\ControlSet001\Services\JLR STONE VCATS TO MES',
       'ImagePath', Value) then
  begin
    ServiceInstallationPath := ExtractFileDir(Value);   
    Result := True;
  end
  else
  begin
    Result := False;
  end;
end;

and in the [RUN] section I put as check the TRUE condition or FALSE condition on this function according the needs...Thanks everybody answering!



来源:https://stackoverflow.com/questions/34680822/use-a-part-of-a-registry-key-value-in-the-inno-setup-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!