문제

I am trying to write a batch file which will ease the process of installing drivers for our users.

The batch file needs to check what version of os (64bit or 32bit) the code is running on and then execute the appropriate .exe.

This is what I have so far:

set os_version=wmic os get osarchitecture
echo "%os_version%"
pause

IF os_version = "64-bit"
@run 64 bit
start /d "%0" CP210xVCPInstaller_x64.exe
ELSE
@run 32 bit
start /d  "%0" CP210xVCPInstaller_x86.exe

Now I am having an issue with assigning the output of the command wmic os get osarchitecture to a variable.

Then I need to check if it is equal to 64-bit and if so execute a .exe in the same location as the bat file?

Second Question is how do I run a .exe from the same directory as the bat file?

도움이 되었습니까?

해결책

This is simpler:

if exist "%SYSTEMDRIVE%\Program Files (x86)\" (
   start "" /d "%~dp0" "CP210xVCPInstaller_x64.exe"
) else (
   start "" /d "%~dp0" "CP210xVCPInstaller_x86.exe"
)

다른 팁

for /f %%a in ('wmic os get osarchitecture^|find /i "bits"') do set "bits=%%a"
echo %bits%

This will handle the "How" to assign the output to the variable. To avoid problems, only the first token in the output of wmic is retrieved (from 32 bits or 64 bits, only the numbers)

MC ND's method needs to be changed to the following...

for /f %%a in ('wmic os get osarchitecture ^| find /i "bit"') do set "bits=%%a"
echo %bits%

Notice the difference in the find /i "bit" vs find /i "bits". Using "bits" will not work as the OSArchitecture only returns 32-bit or 64-bit, not bits.

if exist %windir%/syswow64 (
   start "" /d "%~dp0"/64 bit program (PE d+) path
) else (
   start "" /d "%~dp0"/32 bit program (PE L) path
)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top