find out user's windows

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

find out user's windows

#1 Post by Mohammad_Dos » 27 Jan 2011 05:40

how to find out user's windows in batch?

if xp echo "you have windows xp"
else echo "you have another windows"

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: find out user's windows

#2 Post by ChickenSoup » 27 Jan 2011 07:44

This may not be the best way, but it works.

Code: Select all

for /f "tokens=2 delims=[]" %%a in ('ver') do set winver=%%a
if "%winver%"=="Version 5.1.2600" (
echo.This is Windows XP
) else (
echo.This is another version of windows.
)

Mohammad_Dos
Posts: 84
Joined: 08 Sep 2010 10:25
Location: Iran,Kashan
Contact:

Re: find out user's windows

#3 Post by Mohammad_Dos » 27 Jan 2011 09:33

Is it possible to use %ERORLEVEL% in this commands?

like this:

ver|find "windows xp"
if %ERORLEVEL% equ 1 echo ...

ChickenSoup
Posts: 79
Joined: 13 Dec 2010 10:32

Re: find out user's windows

#4 Post by ChickenSoup » 27 Jan 2011 09:49

Good point. Not sure why i didn't look this way sooner...

Code: Select all

ver|findstr /c:"5.1.2600" && echo.windows xp || echo.not XP

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: find out user's windows

#5 Post by aGerman » 28 Jan 2011 13:45

Another way is to read the registry keys.

Code: Select all

@echo off &setlocal
for /f "tokens=1,2*" %%a in ('reg Query "HKLM\Software\Microsoft\Windows NT\CurrentVersion"') do (
  if /i "%%a"=="CurrentBuildNumber" set "build=%%c"
  if /i "%%a"=="CurrentVersion" set "version=%%c"
  if /i "%%a"=="ProductName" set "name=%%c"
)

echo %build%
echo %version%
echo %name%
pause

Mostly %version% would be good enough for determining.

http://msdn.microsoft.com/en-us/library/ms724832%28v=vs.85%29.aspx

Regards
aGerman

Post Reply