-1

i have a problem with my code, i was programming something that will install all .net frameworks the directx 9.0c patch if nessessery and some other things

The code echo off

echo \====================================/
echo / A repackage of all essential files \
echo \ that are required to be installed  /
echo / so installing them manually isn't  \
echo \ a big problem.                     /
echo /====================================\
echo \    Continue at your own risk!!!    /
echo /====================================\
echo.
echo Type yes to continue or no to cancel:
set /p Reponse=""
cls
if %Reponse% == yes (
echo what's is your CPU architecture? 32-Bit or 64-Bit?
echo to help, look at your ram, if it's below the 4GB Then its 32-bit
set /p arch=""
if %arch% == 32-bit (
cls
echo starting Installation
)
echo starting installation process
)
if %Reponse% == no (
echo Shutting Down
echo Thank you for your participation
)
pause

The broken part:

if %Reponse% == yes (
echo what's is your CPU architecture? 32-Bit or 64-Bit?
echo to help, look at your ram, if it's below the 4GB Then its 32-bit
set /p arch=""
if %arch% == 32-bit (
cls
echo starting Installation
)
echo starting installation process
)

it's working when this part of the code isn't present:

echo what's is your CPU architecture? 32-Bit or 64-Bit?
echo to help, look at your ram, if it's below the 4GB Then its 32-bit
set /p arch=""
if %arch% == 32-bit (
cls
echo starting Installation
)

Any improvements will be appreciated

Thanks for reading

And sorry for my bad english

  • 1
    You've not explained the problem you're having with the code. *if statement isnt working* is not a useful problem description. In what way is it *not working*? – Ken White Jul 27 '16 at 01:58
  • 1
    If you want to initialize and then use a variable (in your case, `%arch%`) inside of a code block, you need [delayed expansion](http://stackoverflow.com/questions/9681863/windows-batch-variables-wont-set). – SomethingDark Jul 27 '16 at 02:06
  • `If Defined ProgramFiles(x86) (Echo On 64 Bit) Else (Echo On 32 Bit)` will tell you without asking. –  Jul 27 '16 at 02:20
  • You could check the **%processor_architecture%** environment variable. That way, on a 32-bit cmd prompt, you will get 32-bit and on the 64-bit cmd prompt you will get 64 bit. – cup Jul 27 '16 at 05:15
  • @user5477777 Don't depend on what a user enters for architecture or what environment variable `PROCESSOR_ARCHITECTURE` returns as its value on 64-bit Windows depends on execution of batch file by 32-bit cmd.exe or 64-bit cmd.exe. On a computer with more than 2 GB RAM and 64-bit CPU there can be nevertheless installed a 32-bit Windows. So what really matters for installing .NET framework packages is the architecture of Windows itself and not architecture of CPU or the architecture of command process currently executing the batch file. – Mofi Jul 27 '16 at 16:47

1 Answers1

0

This has to do with how environment variables are expanded inside of blocks in a batch file. To override this behavior, use setlocal enabledelayedexpansion and use ! instead of % to reference the environment variable.

@echo off
setlocal enabledelayedexpansion

  ... existing code here ...

if %Reponse% == yes (
echo what's is your CPU architecture? 32-Bit or 64-Bit?
echo to help, look at your ram, if it's below the 4GB Then its 32-bit
set /p arch=""
if !arch! == 32-bit (
cls
echo starting Installation
)
echo starting installation process
)
Anon Coward
  • 9,784
  • 3
  • 26
  • 37