batch file to check 64bit or 32bit OS
batch file to check 64bit or 32bit OS
Can I check to see if current machine is running 64bit OS or 32bit *OS* inside a batch file?
EDIT:
Found this online and it is good enough to me now:
Answer by ThierryB for batch file to check 64bit or 32bit OS
Seems to work if you do only these:
echo "%PROCESSOR_ARCHITECTURE%"
I've found these script which will do specific stuff depending of OS Architecture (x64 or x86):
@echo off echo Detecting OS processor type if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto 64BIT echo 32-bit OS \\savdaldpm01\ProtectionAgents\RA\3.0.7558.0\i386\DPMAgentInstaller_x86 /q goto END :64BIT echo 64-bit OS \\savdaldpm01\ProtectionAgents\RA\3.0.7558.0\amd64\DPMAgentInstaller_x64 /q :END "C:\Program Files\Microsoft Data Protection Manager\DPM\bin\setdpmserver.exe" -dpmservername sa
Try to find a way without GOTO please...
For people whom work with Unix systems, uname -m
will do the trick.
Answer by Steve-o for batch file to check 64bit or 32bit OS
PROCESSOR_ARCHITECTURE=x86
Will appear on Win32, and
PROCESSOR_ARCHITECTURE=AMD64
will appear for Win64.
If you are perversely running the 32-bit cmd.exe
process then Windows presents two environment variables:
PROCESSOR_ARCHITECTURE=x86 PROCESSOR_ARCHITEW6432=AMD64
Answer by Kerstin Fischer for batch file to check 64bit or 32bit OS
I use either of the following:
:CheckOS IF EXIST "%PROGRAMFILES(X86)%" (GOTO 64BIT) ELSE (GOTO 32BIT) :64BIT echo 64-bit... GOTO END :32BIT echo 32-bit... GOTO END :END
or I set the bit
variable, which I later use in my script to run the correct setup.
:CheckOS IF EXIST "%PROGRAMFILES(X86)%" (set bit=x64) ELSE (set bit=x86)
or...
:CheckOS IF "%PROCESSOR_ARCHITECTURE%"=="x86" (set bit=x86) else (set bit=x64)
Hope this helps.
Answer by zzeroo for batch file to check 64bit or 32bit OS
Here's my personal favorite, a logical bomb :)
::32/64Bit Switch ECHO %PROCESSOR_ARCHITECTURE%|FINDSTR AMD64>NUL && SET ARCH=AMD64 || SET ARCH=x86 ECHO %ARCH% PAUSE
With the AND's (&&
) and OR's (||
) this is a IF THEN ELSE
Batch Construct.
Answer by teh_senaus for batch file to check 64bit or 32bit OS
None of the answers here were working in my case (64 bit processor but 32 bit OS), so here's the solution which worked for me:
(set | find "ProgramFiles(x86)" > NUL) && (echo "%ProgramFiles(x86)%" | find "x86") > NUL && set bits=64 || set bits=32
Answer by Adil Hindistan for batch file to check 64bit or 32bit OS
I usually do the following:
:Check_Architecture if /i "%processor_architecture%"=="x32" ( IF NOT DEFINED PROCESSOR_ARCHITEW6432 ( REM Run 32 bit command ) ELSE ( REM Run 64 bit command ) ) else ( REM Run 64 bit command )
Answer by Mahesh for batch file to check 64bit or 32bit OS
*** Start *** @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" ) *** End ***
reference http://support.microsoft.com/kb/556009
Answer by panako for batch file to check 64bit or 32bit OS
'ProgramFiles(x86)' is an environment variable automatically defined by cmd.exe (both 32-bit and 64-bit versions) on Windows 64-bit machines only, so try this:
@ECHO OFF echo Check operating system ... if defined PROGRAMFILES(X86) ( echo 64-bit sytem detected ) else ( echo 32-bit sytem detected ) pause
Answer by Michael for batch file to check 64bit or 32bit OS
After much trial and error, I managed to get a few different working examples, but the kicker was when the batch was launched on a 64bit OS on a 32bit CMD. In the end this was the simplest check I could get to work, which works on Win2k-Win8 32/64. Also big thanks to Phil who helped me with this.
set bit64=n if /I %Processor_Architecture%==AMD64 set bit64=y if /I "%PROCESSOR_ARCHITEW6432%"=="AMD64" set bit64=y
Answer by Emil Re?a Enriquez for batch file to check 64bit or 32bit OS
run this in command prompt start->type cmd and enter the command below
wmic os get osarchitecture
Answer by Rory for batch file to check 64bit or 32bit OS
Here's a nice concise version:
set isX64=False && if /I "%PROCESSOR_ARCHITECTURE%"=="AMD64" ( set isX64=True ) else ( if /I "%PROCESSOR_ARCHITEW6432%"=="AMD64" ( set isX64=True ) ) echo %isX64%
Don't use the "Program Files (x86)" directory as evidence of anything: naughty software can easily create this directory on a 32-bit machine. Instead use the PROCESSOR_ARCHITECTURE and PROCESSOR_ARCHITEW6432 environment variables.
Answer by Sam Spade for batch file to check 64bit or 32bit OS
This is the correct way to perform the check as-per Microsoft's knowledgebase reference ( http://support.microsoft.com/kb/556009 ) that I have re-edited into just a single line of code.
It doesn't rely on any environment variables or folder names and instead checks directly in the registry.
As shown in a full batch file below it sets an environment variable OS equal to either 32BIT or 64BIT that you can use as desired.
@echo OFF reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT if %OS%==32BIT echo This is a 32bit operating system if %OS%==64BIT echo This is a 64bit operating system
Answer by Dalir Bajlany for batch file to check 64bit or 32bit OS
Many DOS commands in the different versions of Windows are similar but may support different parameters. Plus, newer versions of Windows may support new commands or retire older ones. Thus, if you wish to write a batch file that can run on different types of machines, it may prove beneficial to determine the version of Windows on which the batch file is running. This way the batch file can execute commands appropriate to the operating system.
The following batch file will determine whether or not the machine is running Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, Windows XP, Windows 2000, or Windows NT. It can easily be modified to support other versions of Windows as necessary or to set an environment variable based on the version of Windows detected. Note that for this batch file to correctly discern between newer versions of Windows Server and consumer versions of Windows, it is more convoluted than batch files you may see elsewhere. I have explained the reasoning below.
1) Open a Notepad window.
2) Copy the following text into Notepad (you may want to access this tip's printed version as some lines wrap):
@echo off ver | find "2003" > nul if %ERRORLEVEL% == 0 goto ver_2003 ver | find "XP" > nul if %ERRORLEVEL% == 0 goto ver_xp ver | find "2000" > nul if %ERRORLEVEL% == 0 goto ver_2000 ver | find "NT" > nul if %ERRORLEVEL% == 0 goto ver_nt if not exist %SystemRoot%\system32\systeminfo.exe goto warnthenexit systeminfo | find "OS Name" > %TEMP%\osname.txt FOR /F "usebackq delims=: tokens=2" %%i IN (%TEMP%\osname.txt) DO set vers=%%i echo %vers% | find "Windows 7" > nul if %ERRORLEVEL% == 0 goto ver_7 echo %vers% | find "Windows Server 2008" > nul if %ERRORLEVEL% == 0 goto ver_2008 echo %vers% | find "Windows Vista" > nul if %ERRORLEVEL% == 0 goto ver_vista goto warnthenexit :ver_7 :Run Windows 7 specific commands here. echo Windows 7 goto exit :ver_2008 :Run Windows Server 2008 specific commands here. echo Windows Server 2008 goto exit :ver_vista :Run Windows Vista specific commands here. echo Windows Vista goto exit :ver_2003 :Run Windows Server 2003 specific commands here. echo Windows Server 2003 goto exit :ver_xp :Run Windows XP specific commands here. echo Windows XP goto exit :ver_2000 :Run Windows 2000 specific commands here. echo Windows 2000 goto exit :ver_nt :Run Windows NT specific commands here. echo Windows NT goto exit :warnthenexit echo Machine undetermined. :exit
3) Save the file as %WINDIR%\whichvers.bat
4) Now, from the command prompt, enter:
whichvers
This will display which version of Windows you are running.
NOTES:
The reasoning for using the SYSTEMINFO command rather than relying on the VER command is because Windows Server 2008 "shares" version numbers with other Windows releases (see Microsoft). Thus relying on a "version number" of 6.0 to detect Windows Vista or 6.1 to detect Windows 7 fails to differentiate a machine from Windows Server 2008 or Windows Server 2008 R2.
The creation of %TEMP%\osname.txt is solely because I could not place the results of systeminfo | find "OS Name" directly into the for /f command - it does not like piped commands. You may find an easier way to handle grabbing the information from SYSTEMINFO - if so, please comment.
The environment variable %vers% has leading spaces. I could remove these with a longer batch file, but in this case it is not necessary.
The batch file detects for SYSTEMINFO as it assumes if it gets beyond the older operating system detections, the running version of Windows is even older and will not have this utility. On Windows 7 64-bit it is still located in the %SystemRoot%\system32 folder - if later versions of Windows become 64-bit only, this batch file may have to be updated.
Return to the Windows XP and DOS page.
Answer by Ahze85283 for batch file to check 64bit or 32bit OS
If $SYSTEM_os_arch==x86 ( Echo OS is 32bit ) else ( ECHO OS is 64bit )
Answer by kgimpel for batch file to check 64bit or 32bit OS
The correct way, as SAM write before is:
reg Query "HKLM\Hardware\Description\System\CentralProcessor\0" /v "Identifier" | find /i "x86" > NUL && set OS=32BIT || set OS=64BIT
but with /v "Identifier" a little bit correct.
Answer by S_R for batch file to check 64bit or 32bit OS
If the script be able to running under Administrator, then it can use the wmi command.
FOR /f "tokens=2 delims==" %%f IN ('wmic os get osarchitecture /value ^| find "="') DO SET "OS_ARCH=%%f" IF "%OS_ARCH%"=="32-bit" GOTO :32bit IF "%OS_ARCH%"=="64-bit" GOTO :64bit ECHO OS Architecture %OS_ARCH% is not supported! EXIT 1 :32bit ECHO "32 bit Operating System" GOTO :SUCCESS :64bit ECHO "64 bit Operating System" GOTO :SUCCESS :SUCCESS EXIT 0
Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 72
0 comments:
Post a Comment