在检查了正确的处理器类型之后,我尝试了两种脚本变体来安装可执行文件。我相信可执行文件可以运行,但是由于某种原因,它无法检查文件是否已经存在。我都将在这里发布。
有人可以帮忙吗?
@echo on
if /i "%processor_architecture%"=="x86" (
if exist "C:\Program Files\Credential Wizard\CredentialWizard.exe" (
echo ***App is Installed Successfully***
) else (\\srvfs01.flymyrtlebeach.com\deployment$\Software\Nervepoint\nam-creds-provider-windows-x86-2.0.4.exe -q)
) else if /i "%processor_architecture%"=="X64" (
if exist "C:\Program Files (x86)\Credential Wizard\CredentialWizard.exe" (
echo ***App is Installed Successfully***
) else (\\srvfs01.flymyrtlebeach.com\deployment$\Software\Nervepoint\nam-creds-provider-windows-x64-2.0.4.exe -q)
)
exit
或者这个
@echo off
Set RegQry=HKLM\Hardware\Description\System\CentralProcessor\0
REG.exe Query %RegQry% | Find /i "x86"
If %ERRORLEVEL% == 0 (
GOTO X86
) ELSE (
GOTO X64
)
:X86
IF NOT EXIST "C:\Program Files\Credential Wizard\CredentialWizard.exe"(start \\srvfs01.flymyrtlebeach.com\deployment$\Software\Nervepoint\nam-creds-provider-windows-x86-2.0.4.exe -q)
GOTO END
:X64
IF NOT EXIST "C:\Program Files (x86)\Credential Wizard\CredentialWizard.exe"(start \\srvfs01.flymyrtlebeach.com\deployment$\Software\Nervepoint\nam-creds-provider-windows-x64-2.0.4.exe -q)
:End
exit
答案 0 :(得分:0)
我建议阅读Microsoft文章
可以在Windows x64上通过目录中的cmd.exe
执行批处理文件
%SystemRoot%\System32
(x64)或%SystemRoot%\SysWOW64
(x86)使用哪个cmd.exe
取决于调用批处理文件的应用程序的体系结构。运行批处理文件的x86安装程序可执行文件会导致该批处理文件被x86 Windows命令处理器解释,因此该批处理文件在32位环境中运行,例如在Windows x86上运行,甚至在Windows x64上执行。
因此,用于安装x86或x64应用程序的批处理文件需要始终首先找出它在哪个环境中由哪个操作系统执行。
此外,PC的CPU具有哪种体系结构都没有关系。它可以是x64处理器,但是仍然安装了Windows x86。在这种情况下,无法使用x64应用程序,尽管由于安装的Windows不支持x64应用程序,因此CPU支持它们。
还有一些其他事实必须考虑:
是否在安装过程中创建了受WOW64影响的注册表项?
在这种情况下,最好是在Windows x64的x86环境中当前正在执行的批处理文件中,在x64环境中再次启动在进行安装之前。
由cmd.exe
立即继续执行的安装程序应用程序执行的批处理文件是否已完成执行该批处理文件?
在这种情况下,必须以32位{ {1}}将暂停,直到在Windows x64上的64位环境中64位cmd.exe
完成执行批处理文件之后,然后在32位环境中不执行任何操作即可退出。
我建议将此批处理文件用于您的任务:
cmd.exe
注意:我添加了一个 FOR 循环,以运行@echo off
rem Is the batch file executed by 32-bit cmd.exe on Windows x86?
if "%ProgramFiles(x86)%" == "" goto DoInstall
rem Is the batch file executed by 64-bit cmd.exe on Windows x64?
if not exist "%SystemRoot%\Sysnative\cmd.exe" goto DoInstall
rem Run this batch file by 64-bit instead of 32-bit cmd.exe on Windows x64.
rem This simple method works only if batch file is executed without arguments.
"%SystemRoot%\Sysnative\cmd.exe" /C "%~f0"
rem Exit batch file executed by 32-bit cmd.exe on Windows x64
rem after 64-bit cmd.exe finished execution of the batch file.
goto EndBatch
:DoInstall
rem echo Processor architecture: %PROCESSOR_ARCHITECTURE%
rem echo Program files directory: %ProgramFiles%
rem echo Common program files: %CommonProgramFiles%
if exist "%ProgramFiles%\Credential Wizard\CredentialWizard.exe" goto Installed
if not "%ProgramFiles(x86)%" == "" if exist "%ProgramFiles(x86)%\Credential Wizard\CredentialWizard.exe" goto Installed
rem When \\srvfs01.flymyrtlebeach.com\deployment$\Software\Nervepoint\
rem contains always just one installer executable for x86 and one for
rem for x64, let the batch file use that one independent on its version
rem number in file name.
for %%I in ("\\srvfs01.flymyrtlebeach.com\deployment$\Software\Nervepoint\nam-creds-provider-windows-%PROCESSOR_ARCHITECTURE%-*.exe") do (
copy /V "%%I" "%TEMP%\%%~nxI"
"%TEMP%\%%~nxI" -q
del "%TEMP%\%%~nxI"
goto ReCheck
)
:ReCheck
if exist "%ProgramFiles%\Credential Wizard\CredentialWizard.exe" goto Installed
if not "%ProgramFiles(x86)%" == "" if exist "%ProgramFiles(x86)%\Credential Wizard\CredentialWizard.exe" goto Installed
echo === ERROR: App installation failed. ===
echo/
pause
goto EndBatch
:Installed
echo *** App is installed successfully. ***
:EndBatch
或nam-creds-provider-windows-x86-2.0.4.exe
或任何其他nam-creds-provider-windows-x64-2.0.4.exe
版本可执行文件2.0.4曾经被更新的版本取代。
即使禁用了命令扩展名,批处理文件也可以使用。
要了解所使用的命令及其工作方式,请打开命令提示符窗口,在其中执行以下命令,并非常仔细地阅读每个命令显示的所有帮助页面。
nam-creds-provider-windows-x*-*.exe
cmd /?
echo /?
exit /?
for /?
goto /?
if /?
pause /?
PS:例如,双击该文件运行rem /?
,然后运行%SystemRoot%\System32\cmd.exe
。让64位命令提示符窗口打开并在Windows资源管理器set pro
中运行,然后双击此文件,然后在32位命令提示符窗口中运行%SystemRoot%\SysWOW64\cmd.exe
。比较两个命令提示符窗口中的输出环境变量。