2016-07-27 68 views
-1

我有一個問題,我的代碼, 我是編程的東西,將所有安裝.NET如果框架中的DirectX 9.0c補丁nessessery和其他一些東西批處理文件編程| if語句不工作

代碼 回聲關閉

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 

損壞部件:

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 
) 

它的工作時,這部分代碼不存在:

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 
) 

任何改進可以理解

感謝您閱讀

很遺憾我的英語不好

+1

你沒有解釋你在代碼中遇到的問題。 *如果陳述不工作*不是有用的問題描述。它以什麼方式*不工作*? –

+1

如果你想初始化,然後在代碼塊中使用一個變量(在你的情況下,'%arch%''),你需要[延遲擴展](http://stackoverflow.com/questions/9681863/windows-batch - 變量,不會設置)。 – SomethingDark

+0

'如果定義ProgramFiles(x86)(64位回聲)否則(回聲在32位)'會告訴你沒有問。 – 2016-07-27 02:20:35

回答

0

這與如何環境變量在批處理文件塊的內部擴展到做。要覆蓋此行爲,請使用setlocal enabledelayedexpansion並使用!而不是%來引用環境變量。

@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 
) 
+0

非常感謝!我從你那裏學到了新東西,再次謝謝你 – user5477777