2017-02-24 48 views
0

我花了很多時間去尋找答案,但仍然不能解決問題如何搜索產品在WMIC中,如果存在使文件

問題: 我需要運行批處理文件文件名,將檢查我的電腦上,如果我已經安裝了框架,如果是的,它將使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。

+1

按照[答案在這裏(http://stackoverflow.com/questions/492967/is-there-a-command-line-command-for-verifying安裝了什麼版本的網絡)有更好的選擇,比如'reg query「HKLM \ SOFTWARE \ Microsoft \ NET Framework Setup \ NDP \ v4 \ Full」/ v版本' – LotPings

+0

週期字符在「沒有實例可用」結束。它永遠不會匹配。 – lit

+1

@LotPings - 有趣的是,使用'reg query'給出的版本號不會出現在'wmic product'輸出中。 – lit

回答

0

解決:

@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 
0

試試這個。

@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" 
) 
相關問題