So, technically, days ago, when I was doing stuffs for my own project, which is WSATools, and then I think I made the most complex way to check operating system's build number before running stuffs.
Why did you do this?
So, Windows Subsystem for Android requires Windows 11, and it requires Windows 11. I also asked Stack Overflow, but technically no solution, which the only ones are just checking the OS version through Command Prompt, but didn't continue running.
The actual command that I used to run it. Modified a little bit so I can explain it
Before you try running
Make sure you downloaded any version of fart.exe. I built a version and included it on WSATools, and you can download v1.99c of fart for Windows here.
ver >> checkver.bat
fart checkver.bat "Microsoft Windows [Version" " " >nul
fart checkver.bat "]" " " >nul
fart -C checkver.bat \r\n " " >nul
fart -C checkver.bat " " "@echo off \r\n echo " >nul
fart checkver.bat " " " " >nul
fart -C checkver.bat ".282 " ".282\r\n" >nul
fart checkver.bat " echo " "echo " >nul
for /f %%N in ('checkver') do set "check=%%N"
if %check% == 10.0.22000.282 (
del checkver.bat
echo Success
pause >nul
) else (
del checkver.bat
echo Failed
)
And now, here's the explanation
ver >> checkver.bat: This is used for getting the ver command output to a batch file.
Which, of course, Opening checkver.bat on any editing software will give us this, which can't be runned directly:
Microsoft Windows [Version 10.0.22000.282]
And in the next step, we will make it runnable by making it echo the OS build number through command prompt and check with the terms at the original file. The output of the file will be something like this:
G:\git-working\wsatools>checkver
10.0.22000.282
The fart checkver.bat commands: a breakdown
Here's what the commands will run, and the output itself:
fart checkver.bat "Microsoft Windows [Version" " "
- Replace
\nMicrosoft Windows [Version 10.0.22000.282]to\n10.0.22000.282]
fart checkver.bat "]" " "
- Replace
\n10.0.22000.282]to\n10.0.22000.282
fart -C checkver.bat \r\n " "
- Remove new line.
fart -C checkver.bat " " "@echo off \r\n echo "
- Transform it into a batch file by adding
echocommand that we will use later. Replaced to@echo off\n echo 10.0.22000.282.
fart checkver.bat " " " "
- Remove some spaces.
fart -C checkver.bat ".282 " ".282\r\n"
- This also removes some spaces. You can replace
.282to the last numbers of the build number. For example:- Windows 10 21H1 (10.0.19043.1202) should replace
.282to.1202
- Windows 10 21H1 (10.0.19043.1202) should replace
fart checkver.bat " echo " "echo "
- Also removes spacing before
echo.
Check output for checkver.bat. It should return just the version.
for /f %%N in ('checkver') do set "check=%%N"
if %check% == 10.0.22000.282 (
del checkver.bat
echo Success
pause >nul
) else (
del checkver.bat
echo Failed
)
For del checkver.bat, this deletes the checkver.bat batch file for future uses.
And finally, compare the output in checkver.bat with the build number set. Change it to if %check == (build number).
Change echo Success to point to the file which you want to run, or just directly put the batch script right there.
Or else, for echo Failed, you can put a failed message there.
Top comments (0)