1

I spend a lot of time to searching for the answer but still cannot solve the problem

Problem: I need to run batch file with fileName that will check on my pc if i have framework installed if yes it will make a fileName_1.txt with a framework version if not i will have empty fileName_0.txt

What i done until now:

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

every loop in for assign everytime the variable

the answer is always fileName_1.txt with couple echo on...

how can i solve it?

tnx.

Leon Barkan
  • 2,676
  • 2
  • 19
  • 43
  • 1
    According to the [answers here](http://stackoverflow.com/questions/492967/is-there-a-command-line-command-for-verifying-what-version-of-net-is-installed) there are better choices like `reg query "HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" /v Version` –  Feb 24 '17 at 20:20
  • The period character was omitted at the end of "No Instance(s) Available." It would never match. – lit Feb 24 '17 at 20:41
  • 1
    @LotPings - Interestingly, using `reg query` gives a version number that does not appear in the `wmic product` output. – lit Feb 24 '17 at 20:43
  • the problem is that the for assign always the last value and the last is empty – Leon Barkan Feb 24 '17 at 20:44
  • the best way is only get the status is it installed or not without the for, can i do it ? – Leon Barkan Feb 24 '17 at 20:45
  • @lit I know, there also isn't a `4.6.` folder in `C:\Windows\Microsoft.NET\Framework` or `C:\Windows\Microsoft.NET\Framework64` –  Feb 24 '17 at 20:59

2 Answers2

1

solved:

@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
Leon Barkan
  • 2,676
  • 2
  • 19
  • 43
0

Try this.

@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"
)