我如何在 WMIC 中搜索产品,如果存在则创建一个文件

how can i search for product in WMIC and if exist make a file

我花了很多时间寻找答案,但仍然无法解决问题

问题: 我需要 运行 带有 fileName 的批处理文件,如果我安装了框架,它将在我的电脑上检查如果是,它将创建一个 fileName_1.txt 框架版本 如果没有,我将有空 fileName_0.txt

到目前为止我做了什么:

@echo off
set pcName=%1
for /f "tokens=1 delims=1" %%A in ('wmic product where "Name like '%%Microsoft .Net Framework 4.6%%'" get version') do set FrameworksVer=%%A

IF "%frameworksVer%"=="No Instance(s) Available" (
@echo Framework 4.6 Not exist >> c:\%pcName%_0.txt
) ELSE (
@echo %FrameworksVer% >> c:\%pcName%_1.txt
)

每次循环赋值变量

答案始终是 fileName_1.txt,并且有情侣回声...

我该如何解决?

tnx.

试试这个。

@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
set "pcName=%~1"
Set "Key=HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"
Set "Version="
For /f "tokens=3" %%A in (
 'reg query "%Key%" /v Version ^|find /i "Version" '
) Do Set "Version=%%A"
If not defined Version (Echo could't evaluate .Net Version&Pause&exit /B 1)
If "%Version:~0,4" neq "4.6." (
  echo Framework 4.6 Not exist >> "c:\%pcName%_0.txt"
) ELSE (
  echo %FrameworksVer% >> "c:\%pcName%_1.txt"
)

已解决:

@echo off
set pcName=%1
for /f "tokens=1 delims=1" %%A in ('wmic product where "Name like '%%Microsoft .Net Framework 4.6%%'" get version') do (
if %%A==4.6.1 goto exist
)

goto notExist

:exist
echo Framework Exist > d:\%pcName%_1.txt
exit

:notExist
echo Framework not exist > d:\%pcName%_0.txt
exit