Bat file if windows version
I don't use the Build value. On more recent versions win 7 onwards you can have powershell do the job for you. None of the previous answers work on Win9x, and will soon fail with w10 22h1. First 4 lines are win3. It then saves the version on wver var, used on comparisons: The leading space on search string is essential to catch the begining of the number in the ver string ie: "4.
Most of previous solutions will soon fail with [future] windows versions. Next w10 22h1 string will be: "Microsoft Windows [Version Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Collectives on Stack Overflow. Learn more. Get Windows version in a batch file Ask Question. Asked 9 years, 2 months ago. Active 1 month ago. Viewed k times. Improve this question. Wai Ha Lee 8, 63 63 gold badges 57 57 silver badges 86 86 bronze badges. Yerko Antonio Yerko Antonio 3 3 gold badges 7 7 silver badges 16 16 bronze badges. I'd be careful here, anyone who took the offer to upgrade to windows 10 may have the old version number in there, my machine was windows 8.
Add a comment. Active Oldest Votes. Improve this answer. Goldorak84 3, 3 3 gold badges 34 34 silver badges 57 57 bronze badges. Jon Jon k 74 74 gold badges silver badges bronze badges. Notice that windows XP has "XP" in the string. Notice the space after XP. The space is required. What is the correct line of code to use? Extract version x. For W10 I like getting the whole version. Thank you. You're answer is what I was looking for. Have you tried using the wmic commands?
Try wmic os get version This will give you the version number in a command line, then you just need to integrate into the batch file. This isn't much more helpful than saying "Try running Ver". WMIC requires an Admin to run it the first time only. So long it is, however i am getting an error with this command, the wmic cli is opening. Nothing is shown in the error..
Improve this question. Wai Ha Lee 8, 63 63 gold badges 57 57 silver badges 86 86 bronze badges. Yerko Antonio Yerko Antonio 3 3 gold badges 7 7 silver badges 16 16 bronze badges. I'd be careful here, anyone who took the offer to upgrade to windows 10 may have the old version number in there, my machine was windows 8. Add a comment.
Active Oldest Votes. Improve this answer. Goldorak84 3, 3 3 gold badges 34 34 silver badges 57 57 bronze badges. Jon Jon k 74 74 gold badges silver badges bronze badges. Notice that windows XP has "XP" in the string. Notice the space after XP. The space is required. What is the correct line of code to use? Extract version x. For W10 I like getting the whole version. Thank you. You're answer is what I was looking for.
Have you tried using the wmic commands? Try wmic os get version This will give you the version number in a command line, then you just need to integrate into the batch file. This isn't much more helpful than saying "Try running Ver". WMIC requires an Admin to run it the first time only. So long it is, however i am getting an error with this command, the wmic cli is opening. Nothing is shown in the error..
Version, 3 Select Case strOsVer case "5. Best part is that unlike others', it works fast. Thank you! This is so much better than most solutions I've been able to find! It should probably print more tokens though e. Badr Elmers Badr Elmers 1, 10 10 silver badges 17 17 bronze badges. It'd be better to save the output of ver to a variable and then echoing that through findstr rather than calling ver 8 times.
Ryan Beesley ver is a builtin command not an external command so it takes the same it will take using echo; I prefer to let it like that for simplicity without using the long for That's a valid point. I don't know if the command has that information built in, I suspect it is still looking at the registry or internal data structure to generate the output, so I would still think it is cleaner to cache it, but it doesn't have the overhead running an external command might.
This will return 5. This method does not use the official Microsoft versions as specified in this table — ZenCodr. Agent Gibbs Agent Gibbs 21 1 1 bronze badge. Mike Swanson Mike Swanson 21 1 1 bronze badge. If you are looking to simply show windows version in a batch file such as Windows 10 etc. Posted by: admin December 19, Leave a comment.
I need to get the OS version with a batch file. This will give you the version number in a command line, then you just need to integrate into the batch file. This table on MSDN documents which version number corresponds to which Windows product version this is where you get the 6. The only drawback of this technique is that it cannot distinguish between the equivalent server and consumer versions of Windows.
Be aware that the extracted version number does not always corresponds to the Windows name release. See below an extract from the full list of Microsoft Windows versions. Please also up-vote answers from Agent Gibbs and peterbh as my answer is inspired from their ideas. This first one is a simple batch way to get the right version. We use this structure inside code to ensure compliance with requirements.
0コメント