Hi, apologies if this sounds ridiculously basic, but I'm new to this and cannot seem to find what I need on the internet, so some help would be brilliant please!
I would like to alter a batch file so that it recognises which OS it is in and then acts accordingly. So for instance, if it's in windows 7, I would need the path set to include "Program Files (x86)", but if it were in XP, the path of the same file that needs to be set would include just "Program Files". Does anyone have any suggestions for how I could do this please?
Thank you in advance. I would really appreciate some assistance.
How to get a batch file to set paths depending on OS?
Moderator: DosItHelp
Re: How to get a batch file to set paths depending on OS?
You may do something like this:
Notes:
I am sure that the list above is incomplete.
Additionally i don't know since when the pathes have been changed,
but you may google this.
Maybe this suffices, too:
But i don't know exact where the change was, and it depends on the path you are using.
penpen
Edit: Shortened the above example and added the below.
Code: Select all
@echo off
setlocal
set "winver[4.1]=Windows 98"
set "winver[4.90]=Windows ME"
set "winver[5.00]=Windows 2000"
set "winver[5.1]=Windows XP"
set "winver[6.0]=Windows Vista"
set "winver[6.1]=Windows 7"
set "winver[6.2]=Windows 8"
set "winver[6.3]=Windows 8.1"
for /F "tokens=2 delims=[]" %%a in ('ver.exe') do (
for /F "tokens=2-4 delims=. " %%b in ("%%a") do (
set "version=%%b", "subversion=%%c", "build=%%d"
)
)
if defined winver[%version%.%subversion%] (
call echo You are using: %%winver[%version%.%subversion%]%%
) else (
echo unknown version, or ver.exe is missing: %version%.%subversion%
)
endlocal
goto :eof
I am sure that the list above is incomplete.
Additionally i don't know since when the pathes have been changed,
but you may google this.
Maybe this suffices, too:
Code: Select all
for /F "tokens=2 delims=[]" %%a in ('ver.exe') do (
for /F "tokens=2-4 delims=. " %%b in ("%%a") do (
set /A "version=%%b", "subversion=%%c", "build=%%d"
)
)
set "myPath=Program Files (x86)"
if %version% == 5 if %subversion% LEQ 1 set "myPath=Program Files"
if %version% LSS 5 set "myPath=Program Files"
penpen
Edit: Shortened the above example and added the below.
Re: How to get a batch file to set paths depending on OS?
I currently got another idea what might work:
penpen
Code: Select all
if defined PROGRAMFILES(X86) ( set "myDir=%PROGRAMFILES(X86)%"
) else set "myDir=%PROGRAMFILES%"
penpen
Re: How to get a batch file to set paths depending on OS?
penpen wrote:penpen
Oooh, this looks hopeful! I'll give it a go, so hopefully I can figure out how to use it properly. Thank you for your help!

Re: How to get a batch file to set paths depending on OS?
penpen,
thanks. was searching for this as well.
thanks. was searching for this as well.
Re: How to get a batch file to set paths depending on OS?
This is what I do but you must be beyond a setlocal to avoid screwing with the path:
if you are in a 32 bit system %ProgramFiles% remains as is.
Code: Select all
setlocal
if defined ProgramFiles(x86) set "ProgramFiles=%ProgramFiles(x86)%"
start "" "%ProgramFiles%\The Program path\The Program.exe"
endlocal&exit/b
if you are in a 32 bit system %ProgramFiles% remains as is.