代码之家  ›  专栏  ›  技术社区  ›  StackBuck

如果应用程序未安装,如何检查是否存在可执行文件并运行安装程序?

  •  -1
  • StackBuck  · 技术社区  · 6 年前

    我是一个没有SCCM的服务器/客户端环境的系统管理员,我想检查组织中的计算机是否有使用批处理文件的文件名。

    我想让脚本检查文件 egui.exe 位于以下目录之一:

    Program Files\ESET\ESET Security\
    Program Files (86)\ESET\ESET Security\
    

    如果文件存在,则脚本应 什么都不做
    如果文件 存在,然后应该启动 Eset端点 在中安装 安静模式 从我的服务器:

    msiexec /i myserver\eea_nt64_enu.msi /qb 
    

    我写了一些东西,但我不确定它是否正确和完整:

    If exist "C:\program files\ESET\ESET Security\egui.exe" echo ?
    else 
    call msiexec /i myserver\eea_nt64_enu.msi /qb
    

    同样,如果文件存在,我不希望脚本加载安装。 如果该文件夹中存在可执行文件,则批处理文件不应执行任何操作。

    如何检查中是否存在可执行文件 程序文件 程序文件(x86) ?

    如何检查每个版本的版本?

    如果防病毒的版本是旧的(比如版本4),那么它应该强制安装并覆盖当前版本?

    2 回复  |  直到 6 年前
        1
  •  1
  •   Mofi    4 年前

    打开命令提示窗口并运行 if /? goto /? 要了解以下批处理文件:

    @echo off
    
    rem This first file existence check works on 32-bit and
    rem 64-bit Windows in 32-bit and 64-bit environment.
    if exist "%ProgramFiles%\ESET\ESET Security\egui.exe" goto :EOF
    
    rem On 64-bit Windows run also a file existence check for 32-bit version
    rem of application in standard program files folder for x86 applications.
    if not "%ProgramFiles(x86)%" == "" if exist "%ProgramFiles(x86)%\ESET\ESET Security\egui.exe" goto :EOF
    
    rem If this batch file is executed by 32-bit cmd.exe on 64-bit Windows
    rem there is still not checked if 64-bit version of application exists
    rem in standard program files folder for x64 applications.
    if not "%ProgramW6432%" == "" if exist "%ProgramW6432%\ESET\ESET Security\egui.exe" goto :EOF
    
    rem Other commands to install the application depending on Windows architecture.
    

    阅读Microsoft文章 WOW64 Implementation Details 因为这些原因 如果 条件

    但我想最好检查一下 egui.exe 通过查询 application registration 此应用程序的注册表项随Microsoft Installer软件包一起安装。

    @echo off
    %SystemRoot%\System32\reg.exe QUERY "HKLM\Software\Microsoft\Windows\CurrentVersion\App Paths\egui.exe" >nul 2>&1
    if not errorlevel 1 goto :EOF
    
    rem Other commands to install the application depending on Windows architecture.
    

    注册 带值退出 1 如果指定的注册表项不存在且具有值 0 成功查询此注册表项时。

    if not errorlevel 1 表示之前执行的命令/应用程序的退出代码为 不大于或等于 1. 也就是说 低于 1. 这意味着几乎所有的命令和应用程序 相同的 0

    我没有 ESET安全 软件包已安装,因此不知道 egui。exe文件 (或此软件包中的任何其他可执行文件)是根据Microsoft Windows应用程序注册指南注册的。

    要了解所有使用的命令及其工作方式,请打开命令提示窗口,在那里执行以下命令,并仔细阅读为每个命令显示的所有帮助页。

    • echo /?
    • 转到/?
    • 如果/?
    • reg /?
    • reg query /?
    • rem /?
        2
  •  1
  •   Stein Åsmul    6 年前

    我假设您已经验证了所讨论的MSI本身并没有处理这个“问题”?它可能有必要的逻辑来清理内置的旧版本,这样您就不需要检查任何前置条件了?

    我看到你得到了一个批量的答案( IF NOT EXIST ),但我想补充一点,您可以使用传统的主动脚本解决此问题( VBScript ,则, Javascript -我知道你可能是一个Javascript人),或者更现代一些 Powershell 脚本(我不怎么使用)。

    我们可以问一下您是如何调用安装的吗?通过登录脚本、计划任务、AD或其他机制?