[英]How to install 32-bit or 64-bit executable if executable does not already exist?
在檢查了正確的處理器類型后,我嘗試了兩種腳本變體來安裝可執行文件。 我相信可執行文件會運行,但由於某種原因,它無法檢查文件是否已經存在。 我會在這里發布兩者。
有人可以幫忙嗎?
@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 位應用程序,盡管 CPU 會支持它們,因為安裝的 Windows 不支持它們。
還有一些其他事實必須考慮:
安裝過程中是否創建了受 WOW64 影響的注冊表項?
在這種情況下,最好在 64 位 Windows 上的 32 位環境中當前正在執行的批處理文件在執行安裝之前在 64 位環境中再次啟動。
是否由安裝程序執行的批處理文件立即在cmd.exe
上繼續執行完成批處理文件?
在這種情況下,有必要暫停 32 位cmd.exe
的批處理文件執行,直到 64 位cmd.exe
在 64 位 Windows 上的 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
注意:我添加了一個FOR循環來運行nam-creds-provider-windows-x86-2.0.4.exe
或nam-creds-provider-windows-x64-2.0.4.exe
或任何其他nam-creds-provider-windows-x*-*.exe
在可執行版本 2.0.4 的情況下會被更新的版本替換。
批處理文件即使在禁用命令擴展的情況下也能工作。
要了解使用的命令及其工作原理,請打開命令提示符窗口,在那里執行以下命令,並仔細閱讀為每個命令顯示的所有幫助頁面。
cmd /?
echo /?
exit /?
for /?
goto /?
if /?
pause /?
rem /?
PS:運行%SystemRoot%\\System32\\cmd.exe
例如雙擊這個文件並運行set pro
。 打開 64 位命令提示符窗口,然后從 Windows 資源管理器%SystemRoot%\\SysWOW64\\cmd.exe
同時雙擊該文件,然后在 32 位命令提示符窗口中運行set pro
。 比較兩個命令提示符窗口中的輸出環境變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.