如果程序存在或不存在,则编写cmd控制台以及bacth文件中的失败/成功



如果使用文件安装或未安装程序,如何写入命令提示符.bat?

请帮助更正代码以添加以下内容:

  1. 执行就是失败/成功
  2. 将输出响应写入 cmd 控制台 。

例如,如果程序存在,它应该像下面这样编写命令提示符主机:

。程序已安装

。未安装程序

法典:

    @ECHO off
    TITLE Check and Install MS Visual C++ Redistributable 2015
    SET LOGPATH=D:ToolInstallC++Log
    IF NOT EXIST %LOGPATH% MD %LOGPATH%
    SET PowerShellScriptPath=C:tempCheck_Prog.ps1
    PowerShell -NoProfile -ExecutionPolicy Bypass -File "%PowerShellScriptPath%" >> %LOGPATH%Redist.log
echo PROGRAM IS ALREADY INSTALLED
If exists MS Visual C++ Redistributable 2015(
echo PROGRAM IS NOT INSTALLED )
    PAUSE 

PowerShell 代码 (C:\temp\Check_Prog.ps1) :

$TargetApp = 'Microsoft Visual C++ 2015 Redistributable (x86)'
$RegPath = @('HKLM:SoftwareMicrosoftWindowsCurrentVersionUninstall*')
If ([Environment]::Is64BitOperatingSystem)
{
    $RegPath += 'HKLM:SoftwareWow6432NodeMicrosoftWindowsCurrentVersionUninstall*'
}
$Result = Get-ItemProperty -Path $RegPath |
  Where-Object { $PSItem.DisplayName -eq $TargetApp -and
                 $PSItem.UninstallString } |
  Select-Object -Property @('DisplayName','Publisher','InstallDate','DisplayVersion','UninstallString')
If ($Null -eq $Result)
{
    Write-Output "Could not find '$TargetApp'. "
}
If exists MS Visual C++ Redistributable 2015(

应该是:

If exist "MS Visual C++ Redistributable 2015" (

(注意(前的空格和名称周围的qoutes)

但是呢:

wmic product where caption="Java Auto Updater" get name /value 2>nul |find "=" >nul && echo yes || echo no
wmic product where caption="Yava Auto Updater" get name /value 2>nul |find "=" >nul && echo yes || echo no

最新更新