windows - 在批处理文件的for循环中使用wmic命令中的变量
问题描述
我无法让这个查询工作:
set APPNAME="App Name"
for /f "skip=1delims= " %%t in ('wmic product where "name=%APPNAME%" get IdentifyingNumber') do set "guid=%%t"& goto printguid
:printguid
echo %guid%
我收到“无效的别名动词”错误。我无法弄清楚我错过了什么。
解决方案
备注WMIC
:不要忘记WMIC的输出是unicode!
<CR>
可以通过将值传递给另一个FOR /F
循环来删除尾随。这也删除了幻影“空白”行(实际上是 a <CR>
)
"APPNAME=VirtualDJ 8"
所以我在我这边测试了这批产品,它的工作率为 5/5
@echo off
Title Get IdentifyingNumber from Application using WMIC
set "APPNAME=VirtualDJ 8"
set "GUID="
echo Please Wait a while ... Getting IdentifyingNumber from this Application "%APPNAME%"
@for /f "skip=1 delims=" %%a in ('"wmic product where name="%APPNAME%" get IdentifyingNumber"') do (
@for /f "delims=" %%b in ("%%a") do if not defined GUID set "GUID=%%~nb"
)
cls
echo The Application "%AppName%" has a Guid like this one : "%GUID%"
pause
推荐阅读
- jquery - 无法读取未定义的属性“速度”
- javascript - Fuse.js 在字符串数组中搜索
- java - 无法在 Java Servlet 上上传文件
- python - `django-cognito-jwt` get_public_key 方法中的 TokenValidator 返回无
- mongodb - 带有 ISO-Date %G 的 MongoDB dateFromString 错误
- asp.net-mvc-4 - 使用 Code-First 的另一个模式中的外键在添加迁移时创建了两次引用的表
- c# - 在 ASP.NET C# 中将 Gridview 行转换为列
- javascript - Qt5 - QML - AirLink RV50 - JavaScript:如何在第三方路由器上自动触发组合框和按钮
- python - 在 Pytorch 教程期间发生 ModuleNotFoundError: 'pycocotools._mask'
- python - 使用 if/else 和 for 循环将项目附加到列表理解中的列表