So try this for loop on your Windows box
for /f "tokens=1,2 delims==" %a in ('wmic service list full^|find /i "pathname"^|find /i /v "system32"') do dir %b
This works just fine for me but when I use the icacls command instead of dir I get an error that says icacls fails to process
for /f "tokens=1,2 delims==" %a in ('wmic service list full^|find /i "pathname"^|find /i /v "system32"') do icacls %b
If I run icacls against any of the output one at a time it works just fine
icacls c:\windows\ehome\ehrecvr.exe
Also I echo the command just to make sure everything looks kosher and it
for /f "tokens=1,2 delims==" %a in ('wmic service list full^|find /i "pathname"^|find /i /v "system32"') do @echo icacls %b
any suggestion?
For the life of me, I can’t figure out why that fails. But using
do call icacls %bseems to get around the problem.But service options are included in %b, and they cause icacls to fail because they are invalid options for icacls.
The simplest solution seems to be to switch to a batch file that calls a subroutine. The unwanted options are stripped by just processing %1.
Just to be safe, better to use
"tokens=1*"in case"appears in any of the paths.