这是获取TeamViewer(任何版本)服务可执行文件位置的字符串:
原文链接:https://www.f2er.com/windows/364859.htmlfor /f "skip=1 delims=" %A in ('wmic path win32_service where "name like 'TeamViewer%'" get pathname') do set POSITION=%A
问题是由wmic引起的,因为它在结果的末尾包含一个空行(在Windows 7命令中),这是输出:
C:\Users\giovanni>for /f "skip=1 delims=" %A in ('wmic path win32_service where "name like 'TeamViewer% '" get pathname') do set POSITION=%A :\Users\giovanni>set POSITION="C:\Program Files\TeamViewer\Version8\TeamViewer_Service.exe" :\Users\giovanni>set POSITION= C:\Users\giovanni>echo %position% ECHO enabled.
如何只使用可执行文件的正确位置获得输出的第二行? (当然也可以跳过最新的一行).
提前谢谢所有人,祝你有个愉快的一天.
乔瓦尼.
这是checktv.bat:
for /f "skip=1 delims=" %%A in ('wmic path win32_service where "name like 'TeamViewer%'" get pathname ^| findstr /r /v "^$"') do set POSITION=%%A echo %POSITION%