如果可执行文件不存在,如何安装32位或64位可执行文件?

用户名

在检查了正确的处理器类型之后,我尝试了两种脚本变体来安装可执行文件。我相信可执行文件可以运行,但是由于某种原因,它无法检查文件是否已经存在。我将两者都张贴在这里。

有人可以帮忙吗?

@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
莫菲

我建议阅读Microsoft文档页面

批处理文件可以在64位Windows上通过cmd.exe目录执行

  • %SystemRoot%\System32 (x64)或
  • %SystemRoot%\SysWOW64 (x86)

使用哪种cmd.exe方法取决于调用批处理文件的应用程序的体系结构。运行批处理文件的32位安装程序可执行文件会导致批处理文件由32位Windows命令处理器解释,因此该批处理文件在32位环境(如在32位Windows上)上运行,即使在64位Windows上执行也是如此。 。

因此,用于安装32位或64位应用程序的批处理文件需要始终首先找出它在哪个环境中由哪个操作系统执行。

此外,PC的CPU具有哪种架构都没有关系。它可以是x64处理器,但是仍然安装了32位Windows。在这种情况下,无法使用64位应用程序,尽管由于安装的Windows不支持CPU,所以CPU将支持它们。

还必须考虑其他一些事实:

  1. 是否在安装过程中创建了受WOW64影响的注册表项?
    在这种情况下,最好在64位Windows上当前在32位环境中执行的批处理文件在安装之前在64位环境中再次启动。

  2. 批处理文件是否由安装程序应用程序执行,该应用程序在cmd.exe完成执行批处理文件后会立即继续运行
    在这种情况下,必须cmd.exe中止32位批处理文件的执行,直到cmd.exe在64位Windows上的64位环境中该批处理文件的64完成执行,然后退出而在32位环境中不执行任何操作。

我建议将此批处理文件用于您的任务:

@echo off
rem Is the batch file executed by 32-bit cmd.exe on 32-bit Windows?
if "%ProgramFiles(x86)%" == "" goto DoInstall

rem Is the batch file executed by 64-bit cmd.exe on 64-bit Windows?
if not exist "%SystemRoot%\Sysnative\cmd.exe" goto DoInstall

rem Run this batch file by 64-bit instead of 32-bit cmd.exe on 64-bit Windows.
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 64-bit Windows
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 32-bit and one for
rem for 64-bit, 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

注意:如果可执行文件的版本2.0.4被更新的版本取代,我添加了一个FOR循环来运行一个nam-creds-provider-windows-x86-2.0.4.exenam-creds-provider-windows-x64-2.0.4.exe多个nam-creds-provider-windows-x*-*.exe

该批处理文件即使在禁用了命令扩展名的情况下也可以使用。

为了了解所使用的命令及其工作方式,请打开命令提示符窗口,在其中执行以下命令,并非常仔细地阅读每个命令显示的所有帮助页面。

  • cmd /?
  • echo /?
  • exit /?
  • for /?
  • goto /?
  • if /?
  • pause /?
  • rem /?

PS:%SystemRoot%\System32\cmd.exe例如,双击该文件运行,然后运行set pro让64位命令提示符窗口打开并在Windows资源管理器中%SystemRoot%\SysWOW64\cmd.exe运行set pro然后双击此文件并在32位命令提示符窗口中运行。比较两个命令提示符窗口中的输出环境变量。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

gfortran:在64位系统中编译32位可执行文件

强制GNU链接器生成32位ELF可执行文件

如何使用mingw-w64编译和链接32位Windows可执行文件

在64位可执行文件中执行64位计算

如何将64位和32位可执行文件绑定为一个?

为什么32位可执行文件不能在WoW64下运行?

在32位和64位计算机上的C / C ++可执行文件

将COBOL编译为Windows的32位可执行文件

为什么我的64位可执行文件比32位可执行文件大3倍?

无法以32位可执行文件(在64位操作系统上)以编程方式访问EFS文件

如何在32位或64位配置中以编程方式运行ANY CPU .NET可执行文件?

如何安装可执行文件

无法在64位Ubuntu上运行32位动态可执行文件

如何查找可执行文件

在64位Debian Jessie上运行32位可执行文件

如何安装build-essential:i386以在64位系统上编译32位可执行文件?

在Ubuntu 13.10中运行32位可执行文件

没有设置可执行位时,如何从CD运行可执行文件?

如果我们可以在64位Windows上运行32位可执行文件,为什么不能将其转换?

C ++可执行文件无法在Windows 7中运行-64位不兼容

Docker容器无法运行使用wget复制的32位iperf可执行文件

为什么当我尝试运行可执行文件时,该可执行文件会说它不存在?

在Ubuntu中哪里可以找到IntelliJ IDEA 64位可执行文件?

从LLVM位代码生成Rust可执行文件

如何在PowerShell中检查要安装的可执行文件是32位还是64位?

将函数调用添加到64位Visual C ++可执行文件中

Cmake 项目中不存在 Qt 可执行文件

如何将 32 位共享库(.so 文件)链接到 32 位可执行文件?

Windows 说 64 位可执行文件是“不受支持的 16 位应用程序”