Command line 从批处理自动化软件更新

Command line 从批处理自动化软件更新,command-line,for-loop,batch-file,registry,software-update,Command Line,For Loop,Batch File,Registry,Software Update,有人能帮我找出Windows批处理文件的代码吗?该文件将在目录中查找可执行文件或安装程序的属性,确定安装程序的版本和产品的名称,将它们存储在变量中,并在注册表中查询已安装的产品?我的想法是,我想将更新复制到一台没有从光盘连接到internet的机器上的文件夹中。我希望从那里执行一个批处理文件,查看软件的版本和名称,将它们存储在变量中,然后查询注册表以查看是否安装了以前的版本。因此,如果我下载了install_flash_player_ax.exe,它应该知道如何在注册表中查找adobe flas

有人能帮我找出Windows批处理文件的代码吗?该文件将在目录中查找可执行文件或安装程序的属性,确定安装程序的版本和产品的名称,将它们存储在变量中,并在注册表中查询已安装的产品?我的想法是,我想将更新复制到一台没有从光盘连接到internet的机器上的文件夹中。我希望从那里执行一个批处理文件,查看软件的版本和名称,将它们存储在变量中,然后查询注册表以查看是否安装了以前的版本。因此,如果我下载了install_flash_player_ax.exe,它应该知道如何在注册表中查找adobe flashplayer。如果可执行文件上的版本比注册表中的版本新,它将进行静默安装


任何帮助或建议都将不胜感激

虽然这是一个老问题,但我会尽力回答它,因为它可能对其他人有用。 Windows命令shell并没有一种直接的方法来获取文件元数据,比如版本,但您可以使用wmic。 主要问题是,软件的显示名称在安装/更新exe文件的属性中可能与注册表中的显示名称不同。因此,从文件元数据中获取名称并在整个HKLM注册表配置单元中查询它是一个坏主意。 此外,如果您没有要更新的软件的预定义列表,并且不知道注册表中存储每个软件版本的确切路径,那么对exe列表进行循环以从其元数据id获取名称的想法也是错误的

因此,最好的搜索方法是分别为每个exe创建一个脚本,并将它们添加到Windows调度程序中。 以下是自动更新Adobe Flash Player for 64位操作系统所需的批处理脚本示例:

@echo off
for /f %%a in ('wmic datafile where name^="C:\\Users\\username\\Downloads\\install_flash_player_19_active_x.exe" get version ^| find /n /v "" ^| findstr "^\[2\]"') do set var=%%a
for /f "tokens=2 delims=]" %%a in ("%var%") do set prver=%%a
echo Available version: %prver%
for /f "tokens=3" %%a in ('reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{EE56217C-B3F9-402B-B4EC-63F090F51D3D}" /v DisplayVersion') do set regversion=%%a
echo Installed version: %regversion%
if %prver% == %regversion% (echo The newest version %regversion% installed) else (echo Update required & "C:\Users\username\Downloads\install_flash_player_19_active_x.exe")
更新文件位于一些本地文件夹中,在我的例子中是C:\Users\username\Downloads\install\u flash\u player\u 19\u active\u x.exe。安装程序后,它们会在中注册自己 HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\适用于64 bot操作系统和 32位的HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\版本

因此,您需要找到所需的每个安装的路径。请注意,我的脚本中的{EE56217C-B3F9-402B-B4EC-63F090F51D3D}是给定版本Flash Player 19的GUID

PowerShell中也有同样的功能,更为优雅:

$filever = (Get-Item "C:\Users\username\Downloads\install_flash_player_19_active_x.exe").versioninfo.fileversion
$appname = (Get-Item "C:\Users\username\Downloads\install_flash_player_19_active_x.exe").versioninfo.internalname
$regpath = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{EE56217C-B3F9-402B-B4EC-63F090F51D3D}"
$regversion = Get-ItemProperty $regpath -Name "DisplayVersion" | select -ExpandProperty "DisplayVersion"
if ($winrarreg -eq $regversion) {
    "The newest version of Flash Player $regpath is already installed"
    } else {
        "Current installed version is:" +  $regversion
        "Available version is:" + $filever
        "Let's update Flash Player"
        Start-Process -FilePath "C:\Users\username\Downloads\install_flash_player_19_active_x.exe"
    }