批处理脚本中的if语句,以便使用netsh将无线配置文件部署到windows计算机



我想自动化无线配置文件的部署。

情况是,有Windows计算机已经连接到网络A。我想为所有计算机部署网络B的新无线配置文件,但那些已经连接到A网络的计算机除外。

以下是我认为我需要什么的大致想法,但我正在努力找到正确的代码。

netsh wlan show profile | find "wireless profile name"
if exist "wireless profile name"
do nothing
else
netsh wlan add profile filename="2nd wireless profile"

我知道最上面一行是有效的,我正在努力解决的部分是if语句以及如何用exist函数检查find的结果。

此任务不需要使用find.exe,只需使用请求查看配置文件返回的ErrorLevel即可:

"%__AppDir__%netsh.exe" WLAN Show Profiles Name="wireless profile name">NUL
If ErrorLevel 1 "%__AppDir__%netsh.exe" WLAN Add Profile FileName="2nd wireless profile"

如果你确信你正在运行的电脑在%PATH%%PATHEXT%下有默认条目,那么你可能会将其缩短为:

NetSH WLAN Show Profiles Name="wireless profile name">NUL
If ErrorLevel 1 NetSH WLAN Add Profile FileName="2nd wireless profile"

最新更新