the question is in the title, I am not sure how to do it. Help would be greatly appreciated!
Page 1 of 1
how can I identify if OS is 32 bit or 64 bit in batch file?
#2
Posted 09 February 2009 - 05:46 PM
>echo %processor_architecture% AMD64
Note that this will not work for a script like RunOnceEx.cmd or similar that are called from cmdlines.txt
I mean, this variable is set when the computer makes the first boot after the installation.
Otherwise, try checking if %WinDir%\SysWOW64 exists...
Or you can use AutoIt (@OSArch constant)
#3
Posted 29 April 2009 - 09:36 AM
I know this is an older post, but here's what I've always used:
If it exists (ERRORLEVEL = 1), then it runs the 64-bit (x64) commands
If it does not exist (ERRORLEVEL = 0), then it runs the stanard 32-bit (x86) commands.
Of course, you could do the same with SysWow64 instead. Just pick any file or folder that would only exist in a 64-bit OS.
%ProgramFiles(x86)% IF ERRORLEVEL = 1 GOTO x64 IF ERRORLEVEL = 0 GOTO x86
If it exists (ERRORLEVEL = 1), then it runs the 64-bit (x64) commands
If it does not exist (ERRORLEVEL = 0), then it runs the stanard 32-bit (x86) commands.
Of course, you could do the same with SysWow64 instead. Just pick any file or folder that would only exist in a 64-bit OS.
#4
Posted 29 April 2009 - 11:49 AM
Jito463, on Apr 29 2009, 04:36 PM, said:
I know this is an older post, but here's what I've always used:
If it exists (ERRORLEVEL = 1), then it runs the 64-bit (x64) commands
If it does not exist (ERRORLEVEL = 0), then it runs the stanard 32-bit (x86) commands.
Of course, you could do the same with SysWow64 instead. Just pick any file or folder that would only exist in a 64-bit OS.
%ProgramFiles(x86)% IF ERRORLEVEL = 1 GOTO x64 IF ERRORLEVEL = 0 GOTO x86
If it exists (ERRORLEVEL = 1), then it runs the 64-bit (x64) commands
If it does not exist (ERRORLEVEL = 0), then it runs the stanard 32-bit (x86) commands.
Of course, you could do the same with SysWow64 instead. Just pick any file or folder that would only exist in a 64-bit OS.
I'd suggest not to use that syntax
IF ERRORLEVEL = n is first of all not correct
Also an errorlevel of 0 means that errorlevel was 0 or greater which in all cases would be true.
This would probably replace your command better
IF EXIST "%PROGRAMFILES(X86)%" (GOTO 64BIT) ELSE (GOTO 32BIT)
#5
Posted 29 April 2009 - 01:01 PM
Just for the record.
Errorlevel in NT based systems is a variable:
http://www.911cd.net...showtopic=18512
http://www.robvander.../errorlevel.php
jaclaz
Errorlevel in NT based systems is a variable:
http://www.911cd.net...showtopic=18512
http://www.robvander.../errorlevel.php
jaclaz
#6
Posted 09 May 2009 - 09:12 AM
Yzöwl, on Apr 29 2009, 12:49 PM, said:
Jito463, on Apr 29 2009, 04:36 PM, said:
I know this is an older post, but here's what I've always used:
If it exists (ERRORLEVEL = 1), then it runs the 64-bit (x64) commands
If it does not exist (ERRORLEVEL = 0), then it runs the stanard 32-bit (x86) commands.
Of course, you could do the same with SysWow64 instead. Just pick any file or folder that would only exist in a 64-bit OS.
%ProgramFiles(x86)% IF ERRORLEVEL = 1 GOTO x64 IF ERRORLEVEL = 0 GOTO x86
If it exists (ERRORLEVEL = 1), then it runs the 64-bit (x64) commands
If it does not exist (ERRORLEVEL = 0), then it runs the stanard 32-bit (x86) commands.
Of course, you could do the same with SysWow64 instead. Just pick any file or folder that would only exist in a 64-bit OS.
I'd suggest not to use that syntax…
IF ERRORLEVEL = n is first of all not correct
Also an errorlevel of 0 means that errorlevel was 0 or greater which in all cases would be true.
This would probably replace your command better
IF EXIST "%PROGRAMFILES(X86)%" (GOTO 64BIT) ELSE (GOTO 32BIT)
It's always worked for me, which is why I used it, but I will admit your version is much cleaner and will probably switch to that. By the way, in your version, the ( ) around the GOTO commands doesn't need to be there.
#7
Posted 09 May 2009 - 11:54 AM
Jito463, on May 9 2009, 04:12 PM, said:
%ProgramFiles(x86)% IF ERRORLEVEL = 1 GOTO x64 IF ERRORLEVEL = 0 GOTO x86
If it exists (ERRORLEVEL = 1), then it runs the 64-bit (x64) commands
If it does not exist (ERRORLEVEL = 0), then it runs the stanard 32-bit (x86) commands.
<snip />
<snip />
It's always worked for me, which is why I used it.
It is wrong, the first line would produce an error every time
'expanded or otherwise variable' is not recognized as an internal or external command, operable program or batch file.
For the next line you could have used among others:
IF ERRORLEVEL 1 GOTO x64
IF %ERRORLEVEL%==1 GOTO x64
IF %ERRORLEVEL% EQU 1 GOTO x64
IF %ERRORLEVEL% GEQ 1 GOTO x64
IF NOT ERRORLEVEL 0 GOTO x64
Jito463 said:
By the way, in your version, the ( ) around the GOTO commands doesn't need to be there.
Run this code in your console window
IF EXIST "%PROGRAMFILES(X32)%" (ECHO/32BIT) ELSE (ECHO/64BIT)Result is:
64BIT
Now run this in your console window
IF EXIST "%PROGRAMFILES(X32)%" ECHO/32BIT ELSE ECHO/64BITWhat is the result?
#8
Posted 11 May 2009 - 06:40 AM
... don't try to fight with yzöwl , he's always win at "batch"
...
Share this topic:
Page 1 of 1



Help
Back to top









