Join 306,920 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,773 people online right now. Registration is fast and FREE... Join Now!
What I want is to use a script to find out what os the program is run on, and save it to a variable that can be accessed by another program, or possibly the same one?
To distinguish between XP and Vista, I have the following for a batch file, however, it is not really clear enough, and only encompasses 2 of a lot of different windows OSs.
CODE
:: Script to find the OS Version :: By Gorian @echo off cd ..
if %OS% == Windows_NT Goto Windows_NT
:Windows_NT set pathXP==C:\Documents and Settings\%USERNAME% set pathVista==C:\Users\%USERNAME%
if /i %USERPROFILE% == %pathXP% Goto XP if /i %USERPROFILE% == %pathVista% Goto Vista Goto Error
:XP set OSVERSION=XP Goto End
:Vista set OSVERSION=Vista Goto End
:Error echo. echo An Error has occured echo. pause Goto End
:End echo %OSVERSION% exit /b
I know that I can use psinfo from the sysinternals to find it, and had code that parsed the output until only the OS version remained...
however, I could not seem to get this into a system variable, i tried different redirection operators > and | and such.... I would like to have in a simpler script, so I can have it as a variable that can be accessed by Batch Files.
I am not asking for code, but some guidance would be appreciated.
This post has been edited by Gorian: 6 Nov, 2009 - 01:02 PM
Maybe you would get an answer on stackoverflow.com? I wouldn't normally recommend for someone to go to a different site, but it's obvious you aren't getting any answers here.
maybe if I was more clear? I chose to use Batch Files because they seemed easiest, but if someone can suggest something else that does not require me to learn a new language...
What I want is a script to find out what OS is being run, and store it to a variable so that it can be called again. This allows me to write scripts for copying, or running programs that call the right path based on the OS. For instance, %appdata% is different in Vista than in XP, and it can be annoying to path things like "%appdata%\..\..\Folder\Folder\file.ext"
With a batch file, I can call the script as call OS_Version.bat and all variables made with the set command are available to be called by the calling script. Plus, it seems to me, without getting complicated in C++, to start programs, one would do a system("Start File.exe"); or shell execute anyway, so it makes sense to use a batch file and save time and space....
This post has been edited by Gorian: 15 Nov, 2009 - 11:53 PM
VER |find /i "Windows 95" > nul IF NOT ERRORLEVEL 1 GOTO 95
VER |find /i "Windows 98" > nul IF NOT ERRORLEVEL 1 GOTO 98
VER |find /i "Windows Millennium" > nul IF NOT ERRORLEVEL 1 GOTO ME
VER | find "XP" > nul IF %errorlevel% EQU 0 GOTO XP
VER | find "2000" > nul IF %errorlevel% EQU 0 GOTO 2000
VER | find "NT" > nul IF %errorlevel% EQU 0 GOTO NT
VER | find /i "Vista" > nul IF %errorlevel% EQU 0 GOTO Vista
VER | find "7" > nul IF %errorlevel% EQU 0 GOTO 7
Else Goto ERROR
:95 Set OS_Version=Windows 95 GOTO :EOF
:98 set OS_Version=Windows 98 Goto EOF
:ME set OS_Version=Windows ME Goto EOF
:XP Set OS_Version=Windows XP Goto EOF
:2000 Set OS_Version=Windows 2000 Goto EOF
:NT Set OS_Version=Windows NT Goto EOF
:Vista Set OS_Version=Windows Vista Goto EOF
:7 Set OS_Version Goto EOF
:ERROR cls Echo. Echo Sorry. Windows has encountered a fatal script problem and must terminate. Echo The Operating System you are running is unknown. Echo. Goto EOF
:EOF (End-of-file) cls exit /b
This post has been edited by Gorian: 16 Nov, 2009 - 06:36 PM
Okay, So last revision? I think I covered the Major ones.... Not any Server OS's though... but it covers Vista and 7 in addition
batch
:: OS Version - To Find what version of Windows is running
@ECHO OFF
::Find Windows
::Windows 95 VER | find /i "4.0" > nul IF NOT ERRORLEVEL 1 GOTO 95
::Windows 98 VER | find /i "4.10" > nul IF NOT ERRORLEVEL 1 GOTO 98
::Windows ME VER | find /i "4.9" > nul IF NOT ERRORLEVEL 1 GOTO ME
::Windows 2000 VER | find /i "5.0" > nul IF NOT ERRORLEVEL 1 GOTO 2000
::Windows XP VER | find "5.1" > nul IF %errorlevel% == 0 GOTO XP
::Windows Vista VER | find /i "6.0" > nul IF %errorlevel% == 0 GOTO Vista
::Windows 7 VER | find "6.1" > nul IF %errorlevel% == 0 GOTO 7
Else Goto ERROR
:95 Set OS_Version=Windows 95 GOTO :EOF
:98 set OS_Version=Windows 98 Goto EOF
:ME set OS_Version=Windows ME Goto EOF
:2000 Set OS_Version=Windows 2000 Goto EOF
:XP Set OS_Version=Windows XP Goto EOF
:Vista Set OS_Version=Windows Vista Goto EOF
:7 Set OS_Version=Windows 7 Goto EOF
:ERROR cls Echo. Echo Sorry. Windows has encountered a fatal script problem and must terminate. Echo The Operating System you are running is unknown. Echo. Goto EOF
:EOF cls exit /b
This post has been edited by Gorian: 17 Nov, 2009 - 04:38 PM