我已成功使用此代码,但是在调整它并在执行netsh命令重命名NIC时使用 - 虽然在写这篇文章时我不确定它是不是最好的路线了。
SET _OSVer=OTHER
FOR /F "Tokens=2 Delims=[]" %%a IN ('VER') DO SET _VerNo=%%a
FOR /F "Tokens=2-3 Delims=. " %%b IN ("%_VerNo%") DO (
IF "%%b.%%c" EQU "5.2" SET _OSVer=2003
IF "%%b.%%c" EQU "6.0" SET _OSVer=2008
IF "%%b.%%c" EQU "6.1" SET _OSVer=2008R2
IF "%%b.%%c" EQU "6.2" SET _OSVer=2012
IF "%%b.%%c" EQU "6.3" SET _OSVer=2012R2
)
IF "%_OSVer%" EQU "2003" (ECHO %_OSVer% )
IF "%_OSVer%" EQU "2008" (ECHO %_OSVer% )
IF "%_OSVer%" EQU "2008R2" (ECHO %_OSVer% )
IF "%_OSVer%" EQU "20012" (ECHO %_OSVer% )
IF "%_OSVer%" EQU "20012R2" (ECHO %_OSVer% )
仅供参考:Pre2012网络标签为Local Area Connection,2012为Ethernet。
我想执行以下命令
netsh interface set interface name = "%NETWORKNAME%" newname = "network-storage" >nul 2>&1
我根据OSversion%NETWORKNAME%进行思考将被定义为" Local Area Connection"或"以太网"
我可以使用
之类的东西 IF "%_OSVer%" EQU "2003" + "2008" + "2008R2" SET Networkname="Local Area Network"
或者有更好的方法吗?
编辑 - 来自Pauls Feeback,最终代码为
SET NICNaming=OTHER
FOR /F "Tokens=2 Delims=[]" %%a IN ('VER') DO SET _VerNo=%%a
FOR /F "Tokens=2-3 Delims=. " %%b IN ("%_VerNo%") DO (
IF "%%b.%%c" LEQ "6.1" SET NICNaming=Local Area Connection
IF "%%b.%%c" GEQ "6.2" SET NICNaming=Ethernet
)
ECHO %NICNaming%
netsh interface set interface name = "%NICNaming%" newname = "network-storage" >nul 2>&1
if %errorlevel%== 0 (Echo found) ELSE (Echo missing abort)
由于 乙
答案 0 :(得分:0)
There对于这样的事情是有价值的答案。
如果我不得不适应,那就是这样的:
@echo off
setlocal
GOTO CHKVERS
:action
rem action
SET "Networkname=Local Area Network"
GOTO:EOF
:CHKVERS
for /f "tokens=4-5 delims=. " %%i in ('ver') do set VERSION=%%i.%%j
if "%version%" == "6.3" goto action &REM Windows 8.1
if "%version%" == "6.2" goto action &REM Windows 8.
if "%version%" == "6.1" goto action &REM Windows 7.
if "%version%" == "6.0" goto action &REM Windows Vista.
echo Version undetermined, please contact an administrator.
endlocal
exit /b 0
您可能也喜欢:
IF "%A%"=="1" IF "%B%"=="1" IF "%C%"=="1" GOTO YES
GOTO NO
您可以使用GEQ和LEQ
IF "%version%" GEQ "6.0" IF "%version%" LEQ "6.3" GOTO YES
GOTO NO
EQU:等于
NEQ:不等于
LSS:小于<
LEQ:小于或等于< =
GTR:大于>
GEQ:大于或等于> =
这个3位数的语法是必要的,因为>和<符号被识别为重定向运算符