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
Solved

Find out OS version in batch file...

Posted on 2012-04-13
5
574 Views
Last Modified: 2012-04-13
Hello everyone, I need to create a batch file that will copy (from a location on C) and replace a single file. However the problem I have is that based on the OS the user is running the file could be in a different location on the hard drive (XP vs Win 7).

Can some tell me how I would check to see what OS they are running in a batch file and then based on that OS go to the correct folder location?

File location:
XP: C:\Documents and Settings\Username\Application Data\Meeting Center\Invitation Cache

Win 7: C:\Users\Username\App Data\Roaming\Meeting Center\ Invitation Cache

Thanks in advance for your help!!
0
Comment
Question by:CCG3
5 Comments
 
LVL 21

Expert Comment

by:motnahp00
ID: 37842732
winver will provide you the OS version installed.
0
 
LVL 6

Expert Comment

by:stavros41
ID: 37842744
Just check for the existance of C:\users or C:\Documents and Settings
0
 
LVL 17

Expert Comment

by:Anuroopsundd
ID: 37842789
REM Check Windows Version
ver | findstr /i "5\.0\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_2000
ver | findstr /i "5\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_XP
ver | findstr /i "5\.2\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_2003
ver | findstr /i "6\.0\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_Vista
ver | findstr /i "6\.1\." > nul
IF %ERRORLEVEL% EQU 0 goto ver_Win7
goto warn_and_exit

:ver_Win7
:Run Windows 7 specific commands here
REM echo OS Version: Windows 7 (debug line)
goto end

:ver_Vista
:Run Windows Vista specific commands here
REM echo OS Version: Windows Vista (debug line)
goto end

:ver_2003
:Run Windows Server 2003 specific commands here
REM echo OS Version: Windows Server 2003 (debug line)
goto end

:ver_XP
:Run Windows XP specific commands here
REM echo OS Version: Windows XP (debug line)
goto end

:ver_2000
:Run Windows 2000 specific commands here
REM echo OS Version: Windows 2000 (debug line)
goto end

:warn_and_exit
echo Machine OS cannot be determined.

:end  




http://www.grimadmin.com/article.php/batchfile-easy-way-to-detect-os-version
0
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 37842800
There's no need at all to check the OS for this; just use the environment variable "APPDATA", which will point to the correct location on every OS since W2k (enter "set appdata" in a command prompt to check).
copy "C:\SomeFolder\whatever.txt" "%APPDATA%\Meeting Center\ Invitation Cache"

Open in new window

Never use a hardcoded "C:\documents and settings\%username%"; always use the environment variable like %USERPROFILE% or, in this case, %APPDATA%.
0
 

Author Comment

by:CCG3
ID: 37843220
Thank you all. I think oBdA is right on target. I just need to set this up and test it on a few machines. I will let you know how it goes. Thanks again everyone!
0

Featured Post

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup" or a blinking cursor with black screen. A loop for Auto repair will start but fix nothing.  You will be panic as there are no back…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

808 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