Hi Frank,
I assume that you are looking for a solution that does not depend on
environment variables.
Therefore I will use an other approach, but this approach is more
complex and has some disadvantages in comparison with my solution
depending on system environment.
If a 32bit cmd.exe is running and a 64bit cmd.exe, too, the following
code can not detect, in which of both cmd.exes the script is running. If
there is a manually created directory %systemdrive%\program files(x86)
the script will return a wrong result. At last the result seems to be
wrong if cmd.exe is invoked by a lnk-file being renamed.
Because of this disadvantages you are strongly recommended to use my
first solution.
The following snippet uses tasklist.exe to list all cmd.exe processes.
It tests, whether the string syswow64 is part of the fully qualified
file name of one of these running cmd.exes. If so one of the running
cmd.exe processes must be a 32bit process on a 64bit system.
The code containes very long lines. All lines that do not begin with two
blanks are accidentally wrapped.
@echo off
set BitSystem=32
set BitConsole=64
if exist "%systemdrive%\program files (x86)" set BitSystem=64
if not exist "%systemdrive%\program files (x86)" set BitConsole=32
if %BitSystem% EQU 64 for /f "tokens=10 delims= " %%i in ('tasklist
/v /fo table /fi "imagename eq cmd.exe" /nh ^| findstr /b /i
/c:cmd.exe') do @(echo %%i | findstr /i /c:syswow64 && set BitConsole=32)
echo running on %BitSystem%bit system in %BitConsole%bit console...
If this does not fit your needs please explain more detailed.