检查操作系统版本和变量的网络标签 [英] Check OS version and variable for Network Label
问题描述
但是,我一直在成功使用此代码,希望对其进行调整并在执行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年以前的网络标签是本地连接",2012年是以太网.
我要执行以下命令
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"
或者有更好的方法吗?
编辑-从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)
谢谢 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
EQU:等于
NEQ:不相等
LSS:小于<
LEQ:小于或等于< =
GTR:大于>
GEQ:大于或等于> =
此3位语法是必需的,因为>和<符号被识别为重定向运算符
I've been using this code successfully however, looking to adjust it and use when performing netsh commands to rename NIC's - although whilst writing this i'm not sure it's the best route anymore.
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% )
FYI: Pre2012 network labels are Local Area Connection, 2012 is Ethernet.
I want to execute the following command
netsh interface set interface name = "%NETWORKNAME%" newname = "network-storage" >nul 2>&1
I'm thinking based on the OSversion %NETWORKNAME% would be defined as either "Local Area Connection" or "Ethernet"
Can I use something like
IF "%_OSVer%" EQU "2003" + "2008" + "2008R2" SET Networkname="Local Area Network"
Or is there a better way to do this?
EDIT - From Pauls Feeback, final code is
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)
Thanks B
There are a valuable answer for such thing.
If I had to adapt, it would be like this:
@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
You may also like:
IF "%A%"=="1" IF "%B%"=="1" IF "%C%"=="1" GOTO YES
GOTO NO
You may use GEQ and LEQ
IF "%version%" GEQ "6.0" IF "%version%" LEQ "6.3" GOTO YES
GOTO NO
EQU : Equal
NEQ : Not equal
LSS : Less than <
LEQ : Less than or Equal <=
GTR : Greater than >
GEQ : Greater than or equal >=
This 3 digit syntax is necessary because the > and < symbols are recognised as redirection operators
这篇关于检查操作系统版本和变量的网络标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!