Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 397 Vote(s) - 3.52 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get Windows version in a batch file

#21
### Why this answer is better than [oHo's answer][1] ? ###
Because it let you:

1. Use arithmetic operators for comparison (`EQU, NEQ, GTR, LSS, LEQ, GEQ`),
for a range of OSes, or if you want one not above or not under a
certain OS, thanks to the leading 0.
2. Easily distinguish between versions of Window 10,11 and vNext (until Windows 40 where the script collapse).
3. Easily test the script using predefind `verString`.

### Explanation ###
- Replace `%verString%` with `'ver'` on a real OS.
- The `if %%i==Version` checks for token #4 to see if its Windows XP or not.
- The arithmetic operators for comparison: `EQU`, `NEQ`, `GTR`, etc.. is done char by char like normal string sorting, so 10.0 is less than 6.3, because 6 is greater than 1.
- So we've to add a leading 0 if Windows is less than 10 for the
comparison to work correctly.
- Rember to use the leading 0 for any comparison.

### Batch ###
```bash
@echo off
set verString="Microsoft Windows [Version 39.0.99999]"
REM set verString="Microsoft Windows [Version 10.0.22621]"
REM set verString="Microsoft Windows [Version 10.0.22000]"
REM set verString="Microsoft Windows [Version 10.0.10240]"
REM set verString="Microsoft Windows [Version 6.3.9600]"
REM set verString="Microsoft Windows [Version 6.1.7601]"
REM set verString="Microsoft Windows XP [Version 5.1.2600]"
REM set verString="Microsoft Windows [Version 4.10]"

Set osName=Unknown Windows
for /f "tokens=4-7 delims=[.] " %%i in (%verString%) do @(if %%i==Version (set os_ver_org=%%j.%%k) else (if %%i geq 10 (set os_ver_org=%%i.%%j.%%k) else (set os_ver_org=%%i.%%j)))
set os_ver=%os_ver_org%
if %os_ver_org:~0,1% gtr 3 set os_ver=0%os_ver_org%

if %os_ver% GEQ 10.0.22000 set osName=Windows 11
if %os_ver% GEQ 10.0.10240 if %os_ver% lss 10.0.22000 set osName=Windows 10
if %os_ver% equ 06.3 set osName=Windows 8.1
if %os_ver% equ 06.2 set osName=Windows 8
if %os_ver% equ 06.1 set osName=Windows 7
if %os_ver% equ 06.0 set osName=Windows Vista
if %os_ver% equ 05.2 set osName=Windows XP x64 or Server 2003
if %os_ver% equ 05.1 set osName=Windows XP
if %os_ver% equ 05.0 set osName=Windows 2000
if %os_ver% lss 05.0 set osName=Windows ME or 98 or less

echo Detected %osName% x%PROCESSOR_ARCHITECTURE:~-2% (%os_ver_org%)
if %os_ver% lss 06.3 echo Only Windows 8.1 or above are supported !
```


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through