I've written some batch code which checks a users system for .NET Core Desktop Runtime v5. If the users system has it, then an appropriate message is displayed. If they don't, they are presented with the opportunity to download it via the correct hyperlink.
Current Code:
@echo off
Title Mod Studio 2 .NET Core Check
:: Check for .Net Core v5
echo:
echo Checking your computer for .Net Core v5 which is required by Mod Studio 2 ...
echo:
setlocal enabledelayedexpansion
set OutputFilename=%TEMP%\MS2netcorecheck.log
:: Send dotnet results to output log file and find relevant core version
dotnet --list-runtimes | find /i "Microsoft.WindowsDesktop.App 5" | find /i /V "-rc" >nul 2>&1
:: If search result is positive then ...
IF %ErrorLevel% EQU 0 (
DEL /F /Q %TEMP%\MS2netcorecheck.log
@dotnet --list-runtimes > "!OutputFilename!"
echo .Net Core v5 is already installed; therefore you do not need to download it.
echo:
echo Please press any key to close this window.
echo:
pause >nul
Goto :SkipDotNet
) else (
DEL /F /Q %TEMP%\MS2netcorecheck.log
@dotnet --list-runtimes > "!OutputFilename!"
echo .Net Core v5 is NOT installed.
echo:
echo Please download and install .Net Core v5 now ...
echo:
echo Please do NOT click on the close button as this will not load the download page.
echo:
echo To be taken to the .Net Core v5 download page now, please press any key.
echo:
pause
)
::Install .Net Core v5
Start "" https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-desktop-5.0.7-windows-x64-installer
:SkipDotNet
However I have been having issues where by it doesn't run correctly on some users systems.
When running the following line of code in cmd by itself (on the users system)
dotnet --list-runtimes | find /i "Microsoft.WindowsDesktop.App 5" | find /i /V "-rc"
Their cmd output is the following:
Microsoft Windows [Version 10.0.19042.1052] (c) Microsoft Corporation. Med enerett.
C:\Users[user]>dotnet --list-runtimes | find /i "Microsoft.WindowsDesktop.App 5" | find /i /V "-rc" 'dotnet' is not recognized as an internal or external command, operable program or batch file.
Is this caused by my code? If so how do I fix it? Or is this an error on their end?
The code works fine on my system but I have .net already installed.
Many thanks for aid in advance.
PS: I know this can also be done in powershell but I require it to be done via batch file.