batch-file - 如何制作脚本来检查计算机中的许可证?
问题描述
我正在尝试制作一个脚本来检查我的计算机中的许可证。我想得到这样的输出:
Name: Windows(R), Professional edition
> PartialProductKey: 3V66T
> LicenseStatus: 1
Name: Office 16, Office16ProPlusVL_KMS_Client edition
> PartialProductKey: WFG99
> LicenseStatus: 1
这是检查Name的代码:
for /f "tokens=2 delims==" %%b in ('"wmic path SoftwareLicensingProduct where (PartialProductKey is not null) get Name /value"') do (echo Name: %%b)
对于PartialProductKey:
for /f "tokens=2 delims==" %%b in ('"wmic path SoftwareLicensingProduct where (PartialProductKey is not null) get PartialProductKey /value"') do (echo PartialProductKey: %%b)
对于LicenseStatus:
for /f "tokens=2 delims==" %%b in ('"wmic path SoftwareLicensingProduct where (PartialProductKey is not null) get LicenseStatus /value"') do (echo LicenseStatus: %%b)
但是如何在每个Name下方显示PartialProductKey、LicenseStatus?谢谢!
解决方案
wmic 对其输出做了一些奇怪的事情(它实际上是 and 之间的交互,添加了一个额外的before 。这种行为在 SO 中被广泛讨论,就像这里一样)。这就是为什么需要:WMIC
FOR /F
\r
\r\n
findstr /V /R "^$"
@echo off
setlocal EnableDelayedExpansion
FOR /F tokens^=*^ delims^=^ eol^= %%L in (
'"wmic path SoftwareLicensingProduct where (PartialProductKey is not null) get Name,PartialProductKey,LicenseStatus /format:list|findstr /V /R "^^$""'
) do (
set "%%L"
echo Name: !name!
echo ^> PartialProductKey: !PartialProductKey!
echo ^> LicenseStatus: !LicenseStatus!
)
推荐阅读
- ruby-on-rails - 登录 JWT 令牌在 localhost 上有效,但在 heroku 上无效——数据错误
- python - 如何使用 python 将 .odt 文件转换为 html
- java - 如果我以编程方式向其添加元素,则 ScrollView 不会滚动
- python - KFold with sklearn.model_selection shuffle 错误
- python - 如何提取像素的ARGB颜色
- arrays - 从以字母开头的列中提取值列表
- php - 标头位置后的PHP做某事
- django - AttributeError: 'NoneType' 对象在尝试使用 Q 过滤器获取最新记录时没有属性 'answer'
- r - 对于每一行,找到最接近指定值的列
- visual-studio - 如何在 Unity 项目中引用外部 DLL 而不将它们提交到存储库中?