@echo off
chcp 1251 > nul
setlocal enabledelayedexpansion
set "regPath=HKLM\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"
for /f "tokens=2,*" %%a in ('reg query "%regPath%" /v Version ^| find "Version"') do (
    set "dotNetVersion=%%b"
)
if not defined dotNetVersion (
    echo To run the Contract Designer, .NET Framework 4.0 is required.
    start "" /wait "%~dp0\dotNetFx40_Full_x86_x64.exe" /passive /promptrestart /showfinalerror
    echo Running Contract Designer...
    start "" "%~dp0\ContractDesigner.exe"
    timeout /t 1 > nul
    exit /b
) else (
    set "dotNetMajorVersion=!dotNetVersion:~,1!"
    if !dotNetMajorVersion! geq 4 (
        echo Running Contract Designer...
        start "" "%~dp0\ContractDesigner.exe"
        timeout /t 1 > nul
        exit /b
    ) else (
        echo To run the Contract Designer, .NET Framework 4.0 is required.
        start "" /wait "%~dp0\dotNetFx40_Full_x86_x64.exe" /passive /promptrestart /showfinalerror
        echo Running Contract Designer...
        start "" "%~dp0\ContractDesigner.exe"
        timeout /t 1 > nul
        exit /b    
    )
)
endlocal
