我希望有人可以帮助我: - )
我需要删除OpenOffice,我发现如何获取ID并将其写入变量,然后通过mcshes删除。但是我无法在变量中写出正确的值。
这是我的代码:
@echo on & setlocal EnableExtensions EnableDelayedExpansion
FOR /F "tokens=*" %%i IN ('wmic product where "name like 'OpenOffice%%'" get IdentifyingNumber /format:value') Do Set id=%%~i
echo Die ID ist %id%
pause
msiexec /uninstall !id! /quiet /norestart
echo OpenOffice Installation Errorlevel %Errorlevel%
pause
答案 0 :(得分:1)
您的for /f
有两个问题:
'
中,也可以在命令中使用它们。 (解决方案usebackq)CR
的行中的额外CRCRLF
而瘫痪
(解决方案,使用另一个处理输出,或解析消除行结束的内容):: Q:\Test\2018\05\15\SO_50349950.cmd
@Echo off&SetLocal EnableExtensions EnableDelayedExpansion
for /f "usebackq tokens=2 delims={}" %%A in (
`wmic product where "name like 'OpenOffice%%'" get IdentifyingNumber /format^:value 2^>NUL`
) Do Set "id={%%~A}"
echo Die ID ist %id%
pause
msiexec /uninstall !id! /quiet /norestart
echo OpenOffice Installation Errorlevel %Errorlevel%
pause
示例输出(搜索此处存在的LibreOffice)
Q:\测试\ 2018 \ 05 \ 15 \ SO_50349950.cmd
Die ID ist {DD7E9D37-CA78-459A-8BA8-29BBF29CF257}
DrückenSieeine beliebige Taste。 。