【问题标题】:How to verify if program is installed in system with pascal?如何使用pascal验证程序是否安装在系统中?
【发布时间】:2022-11-03 01:33:35
【问题描述】:

我不想验证用户是否在他们的系统中安装了 docker。 如果已安装,则继续进行,否则会出现消息框错误。

以前我在 Windows 中查看注册表组,但它的方法不正确。 我想检查 cmd 是否为命令“docker”继续提供输出,如果没有其他消息框。

function GetHKLM: Integer;
begin
  if IsWin64 then
    Result := HKLM64
  else
    Result := HKLM32;
end;

function GetHKU: Integer;
begin
  if IsWin64 then
    Result := HKCU64
  else
    Result := HKCU32;
end;

function InitializeSetup: Boolean;
begin
  // Opening the setup installer initially
  Result := True;
  //if the docker is present in the machine registry return True else checking user registry
  if not RegKeyExists(GetHKLM, 'SOFTWARE\Docker Inc.') then
  begin
    if not RegKeyExists(GetHKU, 'Software\Docker Inc.') then
    begin   
      // return False to prevent installation to continue 
      Result := False;
      // Display that you need to install docker.
      SuppressibleMsgBox('<Docker not found!>', mbCriticalError, MB_OK, IDOK);
    end;
  end;
end;

如何仅使用 cmd 执行此操作?而不是检查注册表。我如何运行命令行并验证输出?

对于等:

function checkdocker() :Boolean;
var
  dockerfound: string;
begin
  Result :=    
    ShellExecute(application.handle, 'docker', nil, nil, SW_MAXIMIZE)
end;

function InitializeSetup: Boolean;
begin
  Result := True;
    if not checkdocker then;
      SuppressibleMsgBox('<Docker not found!>', mbCriticalError, MB_OK, IDOK);
    else
      #continue
    end;

【问题讨论】:

    标签: inno-setup pascalscript


    【解决方案1】:

    要回答您的字面问题:只需使用 Exec 并检查结果代码:

    function CheckDocker: Boolean;
    var
      ResultCode: Integer;
    begin
      Result :=
        Exec('docker', '', '', SW_HIDE, ewWaitUntilTerminated, ResultCode) and
        (ResultCode = 0);
      if Result then Log('Succeeded executing docker')
        else Log('Failed to execute docker');
    end;
    

    (基于How to get an output of an Exec'ed program in Inno Setup?


    虽然有更有效的方法来检查 docker.exe 可执行文件是否在搜索路径中。使用FileSearch。见How can I check SQLCMD.EXE if it is installed on client in Inno Setup

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-25
      • 2012-04-08
      • 1970-01-01
      • 2010-09-11
      • 1970-01-01
      • 2014-01-24
      • 2018-01-04
      • 2013-01-25
      相关资源
      最近更新 更多