批处理文件复制和启动可执行体由架构
问题描述:
我想创建一个登录批处理文件,从服务器复制到用户的本地机器的32位和64位可执行文件,然后执行这些文件基于操作系统类型/建筑。这是我迄今为止,它似乎并没有工作,因为它只启动32位文件,并没有检测和启动64位文件。我是新来的,所以任何援助将不胜感激。批处理文件复制和启动可执行体由架构
@echo off
c:
MD c:\temp
xcopy \\server\NETLOGON\SEPRemoval c:\temp /e /y
cd c:\temp
if /i "%PROCESSOR_ARCHITECTURE%" EQU "x86" goto ARCH32
if /i "%PROCESSOR_ARCHITECTURE%" EQU "AMD64" goto ARCH64
:ARCH32
start /wait SEPprep.exe
goto done
:ARCH64
start /wait SEPprep64.exe
goto done
:done
timeout 15
cd \
del c:\temp /q
exit
答
问题不是你的批处理文件,而是你依赖的环境变量不会做你认为它的工作。
在我的64位Windows 7的机器,ENV
显示:
PROCESSOR_ARCHITECTURE=x86
PROCESSOR_ARCHITEW6432=AMD64
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 42 Stepping 7, GenuineIntel
PROCESSOR_LEVEL=6
...所以依靠PROCESSOR_ARCHITECTURE区分32之间& 64位机器是行不通的。
There is a Microsoft Knowledge Base article on the topic。
修复了检测处理器体系结构的方法,你应该没问题。
答
退房systeminfo
%SystemRoot%\system32\systeminfo.exe
或者一些简单的像
if defined ProgramFiles(x86)
这将检查PROGRAMFILES(x86)的环境变量定义(仅在Windows 64个版本中定义)。
答
这是我终于想出了与援助工作从Microsoft脚本专家论坛,一些人过来:
@echo off
c:
MD c:\temp
xcopy \\server\NETLOGON\SEPRemoval c:\temp\ /e /y
cd /d c:\temp
if {%PROCESSOR_ARCHITEW6432%} EQU {} (
set TRUE_ARCH=%PROCESSOR_ARCHITECTURE%
start /b /wait SEPprep.exe
goto Done
) else (
set TRUE_ARCH=%PROCESSOR_ARCHITEW6432%
start /b /wait SEPprep64.exe
goto Done
)
echo Processor Architecture is %PROCESSOR_ARCHITECTURE%
:Done
timeout 15
rd /s /q c:\temp 1>nul 2>nul
exit
感谢抬起头。我会继续努力的。 – t3kg33k
在StackOverflow中搜索“PROCESSOR_ARCHITECTURE”会发现197个结果......机会是_somebody_发布了您需要的确切代码! – Mogsdad