Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Problem without solution?

Apr
14
0
hello all,

still evaluating the program (x64) on Windows 7 Ultimate.

This simple fragment causes a problem:

if %PROCESSOR_ARCHITECTURE% equ "x86" (
set programdir=%programfiles%
) else (
set programdir=%programfiles(x86)%
)

If TCMD.ini doesn't contain the CMDVariables=Yes option the programdir variable is evaluated incorrectly. If the option is present, programdir evaluates correctly but I'm not able to see variable values in the watch window.

How to resolve?
Salvatore

P.S.: I had to edit this post eight times to be able to insert all text... :-)
 
Salvatore, I assume you are trying to locate a specific executable (or executables). I need to locate devenv.exe on either 32 or 64 bit systems when running our unit test build script. I do the following:
Code:
set devenv=%@regquery[HKCU\Software\Microsoft\VisualStudio\10.0_Config\InstallDir]devenv.exe
If you *have* to have CMD compatibility, then you could do it this way:
Code:
for /f "skip=2 tokens=2*" %f in ('reg query HKCU\Software\Microsoft\VisualStudio\10.0_Config /v InstallDir') do set devenv=%gdevenv.exe
-Scott
 
good morning,
Salvatore, I assume you are trying to locate a specific executable (or executables).
no, no, no. I'm simply assigning the correct program files folder to the variable depending on the architecture for later use. As you know, the 32 bit program files folder on 64 bit systems has a " (x86)" appended to the classic (localized) Program Files name. I cannot add it manually because parenthesis are seen as errors in multi-command if's statements (see batch example in my original message). If I use the CMDVariables=Yes option the system variable is evaluated correctly, but it seems that I'm no longer able to watch variables when debugging, example: Watching the programdir variable the content shown is %programdir instead of the real value. If I don't use the CMDVariables option, TC cannot evaluate the environment variable correctly due to presence of the parenthesis in its name.

S.
 
Code:
set programdir=%@shfolder[42]
if not defined programdir set programdir=%@shfolder[38]
 
Charles, I was going to say that @shfolder[42] doesn't exist on 32 bit systems. But Salvatore also said something about needing the scripts to run in CMD.
 
How To Check If Computer Is Running A 32 Bit or 64 Bit Operating System

http://support.microsoft.com/kb/556009

You can use the following registry location to check if computer is running 32 or 64 bit of Windows Operating System:

HKLM\HARDWARE\DESCRIPTION\System\CentralProcessor\0

You will see the following registry entries in the right pane:

Identifier REG_SZ x86 Family 6 Model 14 Stepping 12
Platform ID REG_DWORD 0x00000020(32)

The above “x86” and “0x00000020(32)” indicate that the Operating System version is 32 bit.

You can also a simple batch file to check the setting on remote computer:

*** 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 ***

You can use PSEXEC (a tool from Sysinternals) to run this script remotely redirect the output in a Text file.

To query registry entry on a remote computer you can use the following statement with Reg.exe:

Reg.exe Query \\computer_name\%Reg_Qry% > checkOS.txt

Please note that you can use the below registry entry to identify the processor architecture:

HKLM\SYSTEM\CurrentCongtrolSet\Control\Session Manager\Envirornment.

You can see the below registry entry in the right pane of the registry editor:

PROCESSOR_ARCHITECTURE REG_SZ x86

Joe
 
Charles, I was going to say that @shfolder[42] doesn't exist on 32 bit systems. But Salvatore also said something about needing the scripts to run in CMD.

This first is easy enough to work around. The second is a more severe handicap!
 
hello,

while I thank you all for your interest in this problem, I also want to better clarify it. The purpose of the batch script is to compile some Delphi components, and one of the requisites is to identify where Delphi is sitting to get the compiler executable. The Delphi IDE is a 32 bit application, so on 32 bit machines the root of the installation is in C:\Program Files\Embarcadero\RAD studio\x.0 while on 64 bit machines it is in C:\Program Files (x86)\Embarcadero\RAD studio\x.0 so a simple interrogation of the PROCESSOR_ARCHITECTURE environment variable is enough to know how to build the path, to which the bin folder is appended (the compiler lives in the bin folder), without inventing fanciful solutions involving the registry or external programs. Running well in CMD also is not an option, and the only problem are CMD limitations that I try to resolve. TC seems to be a good help when building batch files, but maintaining CMD compatibility is also not an option.

Salvatore
 
hello,

after fighting for a couple of hours on internet, this seems to be the only solution that works both in CMD and TC:

Code:
set _tmp1=%programfiles%
rem extracts the last 2 characters from variable
set _cpu=%PROCESSOR_ARCHITECTURE:~-2%
if %_cpu% equ 64 (
  set _tmp2= ^(x86^)
)
set programdir=%_tmp1%%_tmp2%
echo %_tmp1%
echo %_tmp2%
echo %programdir%

Tested and it works in both environments. BTW, is there any comprehensive guide to all the possible tricks in batch files?

Salvatore
 
mmmh, simplified version that works:

Code:
rem extracts the last 2 characters from variable
set _cpu=%PROCESSOR_ARCHITECTURE:~-2%
if %_cpu% equ 64 (
  set programdir=%programfiles% ^(x86^)
) else (
  set programdir=%programfiles%
)
set _cpu=
echo %programdir%

As you can see in both examples, I don't use the ProgramFiles(x86) environment variable any longer, but the substance doesn't change.

Salvatore
 

Similar threads

Back
Top