Page 1 of 1
Establishing the OS (Win 7 / Vista or XP) in the batch
Posted: 23 Jul 2012 13:21
by mr_wizard
I have a batch I'm working up that offers a number of choices via a dos window menu for the end user to choose. These options perform a wide variety of operations in regard to PC maintenance / tune up. A lot of these operations are OS dependent, where I have to modify the directory on the command line in order to tell the batch where to go. I was thinking the most simple way of doing this is just checking for the existence of the "User" folder under the root directory, which would tell us what the OS is, and I can simply put this statement down before each variable so it knows which way to do it.
For example:
:1
@echo off
if blabla | RENAME "C:\Documents and Settings\%USERNAME%\Application Data\Thomson Financial\Thomson ONE\Workspaces" Workspaces.%DATE%
if blabla | RENAME "C:\Users\%USERNAME%\Appdata\Roaming\Thomson Financial\Thomson ONE\Workspaces" Workspaces.%DATE%
if not @echo Undetected Operating System
echo.
echo Finished.
echo.
pause
exit
Clearly I'm not sure what to put in blabla. It would have to see the user folder or not, and perform said operations. Also, I'm not 100% sure the "if not @echo Undetected Operating System" statement will work as an error as well. Can anyone shed some light? Much appreciated!
Re: Establishing the OS (Win 7 / Vista or XP) in the batch
Posted: 23 Jul 2012 13:23
by Squashman
Why not use the VER command?
Re: Establishing the OS (Win 7 / Vista or XP) in the batch
Posted: 23 Jul 2012 13:35
by mr_wizard
Learn something new every day. Wow.
So would it look something like this:
:1
@echo off
if VER=Microsoft Windows XP | RENAME "C:\Documents and Settings\%USERNAME%\Application Data\Thomson Financial\Thomson ONE\Workspaces" Workspaces.%DATE%
if VER=Microsoft Windows Vista | RENAME "C:\Users\%USERNAME%\Appdata\Roaming\Thomson Financial\Thomson ONE\Workspaces" Workspaces.%DATE%
if VER=Microsoft Windows 7 | RENAME "C:\Users\%USERNAME%\Appdata\Roaming\Thomson Financial\Thomson ONE\Workspaces" Workspaces.%DATE%
if not @echo Undetected Operating System
echo.
echo Finished.
echo.
pause
exit
Re: Establishing the OS (Win 7 / Vista or XP) in the batch
Posted: 23 Jul 2012 13:44
by Squashman
It is a command. Not a variable. You will need to put it into a FOR LOOP to assign it to a variable.
I don't recall what the VER command outputs on Vista and Windows 7. You will need to run it on each computer.
you don't need the PIPE in there.
Re: Establishing the OS (Win 7 / Vista or XP) in the batch
Posted: 23 Jul 2012 14:20
by mr_wizard
Noted.
30 minutes now messing with the FOR command and can't seem to get the syntax right. This is where I'm at:
For /D "Users==" %i IN C: DO @echo Successfully found the Users folder.
"Users==" was unexpected at this time.
Anyone mind providing the correct context? Not sure how this would work with the VER command, not grasping the help instructions for it
Maybe my brains just ready to go home.
Re: Establishing the OS (Win 7 / Vista or XP) in the batch
Posted: 23 Jul 2012 14:35
by mr_wizard
Ok that command was a little too much, I found this instead:
systeminfo | find "Windows XP"
if %ERRORLEVEL% == 0 goto WinXP
systeminfo | find "Windows 7”
if %ERRORLEVEL% == 0 goto Win7
Only issues is, if I tell it to go to any one of those points, I have 11 different options in my menu that will need to go to their specific commands for that OS... so while I suppose this would work, I would just have a ton of unique goto's
Re: Establishing the OS (Win 7 / Vista or XP) in the batch
Posted: 23 Jul 2012 15:15
by Squashman
Code: Select all
for /F "tokens=2 Delims=[]" %%G in ('ver') do echo %%G
Re: Establishing the OS (Win 7 / Vista or XP) in the batch
Posted: 23 Jul 2012 16:57
by foxidrive
This should work:
Code: Select all
set "windows="
VER | find " 4.1." > nul && set windows=W98
VER | find " 4.0." > nul && set windows=NT
VER | find " 5.0." > nul && set windows=W2K
VER | find " 5.1." > nul && set windows=XP
VER | find " 5.2." > nul && set windows=2003
VER | find " 6.0." > nul && set windows=Vista or server 2008
VER | find " 6.1." > nul && set windows=Win7 or server 2008 R2
VER | find " 6.2." > nul && set windows=Windows 8
if not defined windows echo unknown operating system
Version info came from here - I'm not sure that both the Win 2008 server values are correct.
http://en.wikipedia.org/wiki/Ver_%28command%29