2016-07-27 69 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