我正在为Windows 10制作“BatchGameHub”,现在我正在使用.batch制作安装程序,但我不知道如何检查Windows版本(10,8,7)并支持if命令。 我的意思是: (检查版本的命令)
if %winversion%== 10 goto start
goto win_not_compatible
:win_not_compatible
echo.
echo Your windows version cannot run gamehub!
echo [ Press any key to cancel installer... ]
echo.
pause>null
exit
答案 0 :(得分:1)
检查Windows内部版本号 - https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832(v=vs.85).aspx
试试这个:
@echo off
for /f "tokens=4,5 delims=,. " %%a in ('ver') do set "build_n=%%a.%%b"
set "Windows10=10.0"
set "Windows8.1=6.3"
set "Windows8=6.2"
set "Windows7=6.1"
set "WindowsVista=6.0"
if exist "%windir%\sysWOW64\" (
set "bitness=64bit"
) else (
set "bitness=32bit"
)
if not "%Windows10%"=="%build_n%" (
goto :not_supported
) else (
goto :start
)
:not_supported
echo not supported
exit /b 1
:start
pause
答案 1 :(得分:1)
要使用WMIC
执行您的问题,请执行以下操作:
@Echo Off
Set "OV="
For /F "Skip=1 Tokens=*" %%A In (
'WMIC OS Where "Version<'4'" Get Version 2^>Nul') Do For %%B In (%%A
) Do Set "OV=%%A"
If Defined OV GoTo Start
Echo=
Echo Your windows version cannot run gamehub!
Echo [ Press any key to cancel installer... ]
Echo=
Pause>Nul
Exit /B
:Start
我仅在Windows 10上使用<
与4
到GoTo Start
,因为字符串比较会发现第一个字符1
小于4
等等(Windows 10或更高版本。)
答案 2 :(得分:0)
可以使用这样的批处理文件:
@echo off
setlocal EnableExtensions DisableDelayedExpansion
rem Get version of Windows enclosed in square brackets from command VER.
for /F "tokens=2 delims=[]" %%I in ('ver') do set "VersionWindows=%%I"
rem Get major and minor version and build number from version information.
for /F "tokens=2-4 delims=. " %%A in ("%VersionWindows%") do (
set "VersionMajor=%%A"
set "VersionMinor=%%B"
set "VersionBuild=%%C"
)
if %VersionMajor% LSS 10 (
echo/
echo Your windows version cannot run gamehub!
echo/
echo [Press any key to cancel installer... ]
echo/
endlocal
pause >nul
exit
)
rem Other commands for installation like:
set "ProcessArchitecture=%PROCESSOR_ARCHITECTURE:~-2%"
if %ProcessArchitecture% == 86 (
set "ProcessArchitecture=32"
) else (
if exist %SystemRoot%\Sysnative\cmd.exe set "ProcessArchitecture=32"
)
echo Your are using Windows version %VersionMajor%.%VersionMinor%.%VersionBuild% %PROCESSOR_ARCHITECTURE%
echo The installation process is running in %ProcessArchitecture%-bit environment.
endlocal
请考虑Microsoft Developer Network(MSDN)文章:
如果批处理文件由cmd.exe
中的32位%SystemRoot%\SysWOW64
或cmd.exe
中的64位%SystemRoot%\System32
执行,则取决于启动批处理文件的过程Windows x64(AMD64)。
以下维基百科文章也可能对此编码任务有所帮助:
要了解使用的命令及其工作原理,请打开命令提示符窗口,执行以下命令,并完全阅读为每个命令显示的所有帮助页面。
echo /?
endlocal /?
exit /?
for /?
if /?
pause /?
rem /?
set /?
setlocal /?
ver /?
设备名称 NUL 为nul
,只有一个L
。像pause>null
这样的行会导致将邮件重定向到名为null
的文件,而不是设备 NUL 。另请参阅MSDN文章Using Command Redirection Operators和Naming Files, Paths, and Namespaces,其中包含许多其他有用信息以及设备名称列表。
最后但并非最不重要的是阅读DosTips论坛主题ECHO. FAILS to give text or blank line - Instead use ECHO/,并在批处理文件中避免将来echo.
,并阅读debugging a batch file。