Page 1 of 1

find out user's windows

Posted: 27 Jan 2011 05:40
by Mohammad_Dos
how to find out user's windows in batch?

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

Re: find out user's windows

Posted: 27 Jan 2011 07:44
by ChickenSoup
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.
)

Re: find out user's windows

Posted: 27 Jan 2011 09:33
by Mohammad_Dos
Is it possible to use %ERORLEVEL% in this commands?

like this:

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

Re: find out user's windows

Posted: 27 Jan 2011 09:49
by ChickenSoup
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

Re: find out user's windows

Posted: 28 Jan 2011 13:45
by aGerman
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