Unlike to know OS version 32 or 64 bit from System Properties
another useful way may be scripting. This is useful because in scripting it may
require a conditional decision depending on the system type. So it has been figured out a number of command-line
processes by which it can be determined that – is the computer running with 64
bit or 32 bit OS. This script should be compatible with Windows XP,
Windows 7, Server 2003 and possibly Windows 2000, 98, me & Server 2000. So
let’s observe a number of batch scripting processes to find the system type.
Process 1: The
following batch command is extracting information from registry & looking
for matching “x86”.
OS Check p1.bat
@echo off
Set
RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% > checkOS.txt
Find /i "x86" < CheckOS.txt >
StringCheck.txt
If %ERRORLEVEL% == 0 (
Echo "This is
32 Bit Operating system"
) ELSE (
Echo "This is
64 Bit Operating System"
)
Del checkOS.txt /f
Del StringCheck.txt /f
pause
Reference: Www.Support.Microsoft.Com
Process 2: The
following batch command is looking for the existence for “ProgramFiles(x86)”.
OS Check p2.bat
@echo off
if defined ProgramFiles(x86) (
@echo yes
@echo Some 64-bit work
) else (
@echo no
@echo Some 32-bit work
)
Pause
Process 3: This should be compatible with Windows XP, Windows 7, Server 2003 and possibly Windows 2000, 98, me & 2000 Server.
OS Check p3.bat
@echo off
:: Let's start out by testing for WMIC:
:_TESTWMIC
WMIC /? >nul 2>&1
if %errorlevel% EQU 9009 (
GOTO _CHECKX86
) ELSE (
GOTO _CHECKOSTYPE
)
:: If we did not find WMIC then we simply go check to see if
the Program Files x86 folder is there. We can check that one of two ways. We
can either check that with the environmental variable %ProgramFiles(x86)% or by
checking to see if the registry entry exists which would be
HKLM/Software/Microsoft/Windows/CurrentVersion /v "ProgramFilesDir
(x86)". If we found WMIC then we go and check what OS we are running which
is pretty simple.
:: We are on an operating system that does not support wmic
os get osarchitecture so we cannot determine whether we are on a 32 or 64 Bit
OS so now we check for the Program (x86) directory as a fallback.
:_CHECKX86
IF NOT "%PROGRAMFILES(X86)%" == "" (
echo I am presumably 64 Bit because I have
"%PROGRAMFILES(X86)%"
) ELSE (
echo I am more than likely a 32 bit OS because I do not have
"%PROGRAMFILES(X86)%"
)
GOTO _SOMEWHERE_ELSE
:: If we found WMIC then we now check for the OS Type. The
command for that is wmic os get name
:_CHECKOSTYPE
FOR /F "tokens=3 delims= " %%a in ('wmic os get
name') Do If /i %%a==XP (GOTO _CHECKX86) ELSE (GOTO _CHECKFORSERVER)
:: The above works if you are just checking for XP however
the server token is #4. That is below
:_CHECKFORSERVER
FOR /F "tokens=4 delims= " %%a in ('wmic os get
name') Do If /i %%a==2003 (GOTO _CHECKX86) ELSE (GOTO _CHECK32)
:: If we got this far then we are on an OS that can handle
this code we will definitely be able to tell whether or not we are on a 64 bit
OS.
:_CHECK32
For /F "tokens=2 delims==,-" %%a In ('wmic os get
osarchitecture /value') Do (
set _osarch=%%a
)
:: Do what you want with %_osarch% now.
echo I am a %_osarch% bit OS.
:: Or utilize an IF statement for it.
:: Do what you want with %_osarch% now.
:: IF _osarch==32 (
:: echo I am a 32 Bit OS
:: ) ELSE (
:: echo I am not a 32 Bit OS
:: )
:: Clear the _osarch variable once you are done with it
Set _osarch=
Pause
To download all the above batch follow the Link. Hope these will help.
No comments:
Post a Comment