我一直在成功地使用这段代码,然而,希望调整它,并在执行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% )
仅供参考:2012年以前的网络标签是Local Area Connection, 2012年是Ethernet。
我想执行以下命令
netsh interface set interface name = "%NETWORKNAME%" newname = "network-storage" >nul 2>&1
我认为基于OSversion %NETWORKNAME%将被定义为"本地连接"或"以太网"
我能不能用
IF "%_OSVer%" EQU "2003" + "2008" + "2008R2" SET Networkname="Local Area Network"
或者有更好的方法来做到这一点?EDIT -来自paul的反馈,最终代码是
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)
谢谢B
这个问题有一个有价值的答案。
如果我必须适应,它会是这样的:
@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
http://ss64.com/nt/if.htmlEQU: Equal
NEQ: Not equal
LSS:小于<</p>
LEQ:小于或等于<=
GTR:大于>
GEQ:>=
这个3位数的语法是必要的,因为>和<符号被识别为重定向操作符>符号被识别为重定向操作符>