![WMIC - 如何检查是否返回空值?](https://linux22.com/image/1431437/WMIC%20-%20%E5%A6%82%E4%BD%95%E6%A3%80%E6%9F%A5%E6%98%AF%E5%90%A6%E8%BF%94%E5%9B%9E%E7%A9%BA%E5%80%BC%EF%BC%9F.png)
我正在制作一个批处理文件来制作计算机日志(我需要在工作中格式化电脑之前保存一些信息...)
因此我找到了一些创建此日志的命令,请参阅:
rem -- Windows Version
wmic OS get Caption, OSArchitecture, ServicePackMajorVersion /format:htable > "%~dp0Config %computername%.html"
rem -- User Account
wmic USERACCOUNT get Caption,Name,PasswordRequired,Status /format:htable >> "%~dp0Config %computername%.html"
rem -- Installed Programs
wmic product get Description, InstallDate, Name, Vendor, Version /format:htable >> "%~dp0Config %computername%.html"
问题出在这个命令上:
wmic nicconfig get Description, MACAddress, IPAddress, IPSubnet, DefaultIPGateway, DNSServerSearchOrder, DHCPEnabled /format:htable >> "%~dp0Config %computername%.html"
在这种情况下,我只需要显示具有MAC地址...
在其他情况下,我这样做仅显示启用适配器:
wmic NIC where NetEnabled=true get Name, Speed, PNPDeviceID /format:htable >> "%~dp0Config %computername%.html"
但是现在,我需要检查值是否为非空。如何检查是否返回非空值?是否只取具有 Mac 地址的值?
我尝试了这个但是没有用:
wmic nicconfig where MACAddress!='' get Description, MACAddress, IPAddress, IPSubnet, DefaultIPGateway, DNSServerSearchOrder, DHCPEnabled /format:htable >> "%~dp0Config %computername%.html"
抱歉我的英语不好=)
答案1
WMIC 使用 SQL 方言。空字符串(0 长度字符串)与 NULL(无值)不同。
wmic nicconfig where "MACAddress is not null" get ...