如果使用.bat文件安装或未安装程序,如何写入命令提示符?
请帮助更正代码以添加以下内容:
例如,如果程序存在,它应该编写命令提示符主机,如下所示:
...程序已安装
或
...程序未安装
代码:
@ECHO off
TITLE Check and Install MS Visual C++ Redistributable 2015
SET LOGPATH=D:\Tool\InstallC++Log
IF NOT EXIST %LOGPATH% MD %LOGPATH%
SET PowerShellScriptPath=C:\temp\Check_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:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*')
If ([Environment]::Is64BitOperatingSystem)
{
$RegPath += 'HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
}
$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'. "
}
答案 0 :(得分:1)
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