Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Command Line to check for XP, Windows 7 and run script accordingly

Posted on 2011-09-28
13
Medium Priority
?
607 Views
Last Modified: 2012-08-27
Looking for a way to make the command line look for Windows XP or Windows 7 and run the correct script accordingly.  I want to keep this a batch file and not a vbs script.  Can you have it check the registry for XP and then GOTO WinXP or GOTO Win7?
0
Comment
Question by:puter_geek
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
13 Comments
 
LVL 3

Expert Comment

by:_-W-_
ID: 36718955
Your first option is to type "winver"

Second option is to type "systeminfo" for a whole lot of information.

But the first would be the best option.
0
 
LVL 13

Expert Comment

by:Govvy
ID: 36718959
ver command line should help
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 36719010
Parsing VER isn't that easy at it seems - you need to translate the parts of the version number into OS releases. E.g. 5.0  is W2000, 5.1 XP, aso. The different ways mentioned above are shown in
http://www.windows-commandline.com/2009/01/find-windows-os-version-from-command.html (for systeminfo) and http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Q_27227527.html (for VER), and several other question on EE.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 10

Accepted Solution

by:
ReneGe earned 1400 total points
ID: 36719208
Here you go

@ECHO OFF

VER | FINDSTR -i /c:"version 5" >NUL && GOTO WXP
VER | FINDSTR -i /c:"version 6" >NUL && GOTO W7

ECHO THE OS IS NEITHER XP OF WINDOWS 7
PAUSE
EXIT

:WXP
ECHO Windows XP
pause
exit

:W7
ECHO Windows 7
pause
exit

Open in new window

0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36719298
Another way

@ECHO OFF


FOR /F "delims=" %%A in ('systeminfo') DO (
	ECHO %%A | FINDSTR -i /c:"WINDOWS XP" >NUL && GOTO WXP
	ECHO %%A | FINDSTR -i /c:"WINDOWS 7" >NUL && GOTO W7
)

ECHO THE OS IS NEITHER XP OF WINDOWS 7
PAUSE
EXIT

:WXP
ECHO Windows XP
pause
exit

:W7
ECHO Windows 7
pause
exit

Open in new window

0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36719354
Why not another one?

@ECHO OFF


FOR /F "delims=" %%A in ('WMIC OS get caption') DO (
	ECHO %%A | FINDSTR -i /c:"WINDOWS XP" >NUL && GOTO WXP
	ECHO %%A | FINDSTR -i /c:"WINDOWS 7" >NUL && GOTO W7
)

ECHO THE OS IS NEITHER XP OF WINDOWS 7
PAUSE
EXIT

:WXP
ECHO Windows XP
pause
exit

:W7
ECHO Windows 7
pause
exit

Open in new window

0
 
LVL 57

Expert Comment

by:Bill Prew
ID: 36719456
If all you are looking to do is differentiate between systems with Windows 7 and earlier systems, then I'd suggest this slightly simplified approach.  If you need to check more versions of windows then let us know that.

ver | findstr /IL " 6.1.7" > NUL && (
  REM put logic for Windows 7 here
) || (
  REM put logic for non Windows 7 here
)

Open in new window

~bp
0
 
LVL 11

Assisted Solution

by:paultomasi
paultomasi earned 600 total points
ID: 36813121
A quick look on Wikipedia lists 2 versions of Win7 (7 and 7SP1) and 2 versions of XP (XP and XP64).

XP        Microsoft Windows XP [Version 5.1.2600]
XP64      Microsoft Windows [Version 5.2.3790]

Win7      Microsoft Windows [Version 6.1.7600]
Win7SP1   Microsoft Windows [Version 6.1.7601]

Open in new window


The only consistency seperating them is the '6.1' (or 6.1.7 as billprew states above) as indicated by the DOS command VER.

This is all very well providing you know you're only testing either XP or Win7. The reason for this is Windows Server 2008 Release 2 has the same version number as Win7.

Win7      Microsoft Windows [Version 6.1.7600]
S2008R2   Microsoft Windows [Version 6.1.7600]

Open in new window


Similarly, Windows Server 2003 is the same version as XP64.

XP64     Microsoft Windows [Version 5.2.3790]
S2003    Microsoft Windows [Version 5.2.3790]

Open in new window


What this all means is that providing your Windows version is either XP or Win7 the easiest method to distinguish between them is to test for the presence of '6.1'. If the version number contains '6.1' then it's Win7 as in the following batch file code:

@echo off

ver | find "6.1" && goto WIN7 || goto WINXP
exit /b


:WIN7
  ::
  :: Your code for Win7
  ::
goto :eof

:WINXP
  ::
  :: Your code for WinXP
  ::
goto :eof

Open in new window


It gets complicated if your batch file has to determine Windows' version if there is a possibility it could be sitting on one the following:

   Server 2008 R2      - Same as Win7

   Server 2003           - Same as XP64

Furthermore, XP and XP64 conatain little similarity ('Version 5.') which is also shared by Server 2003 and Win2K.
0
 
LVL 7

Author Closing Comment

by:puter_geek
ID: 36933166
Splitting the points.  ReneGe had the most of what I was looking for, but Paultomasi had the 64bit versions as well.

Thanks all!!
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36933180
Gald I could help!
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 36933790
Well done ReneGe....
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36934670
Thanks pal!

Comming from you means a lot!

Cheers
0
 
LVL 11

Expert Comment

by:paultomasi
ID: 36934867
No probs...
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question