WMIC command not working in .bat file

2.3k views Asked by At

I'm new to WIMC so probably there will be simple answer to my question.

If I will open CMD and run this command:

wmic /OUTPUT:C:\LogServices.txt service where "not PathName like '%Windows%'" get DisplayName,Name,PathName,State,StartMode

this will generate file with all services not in windows folder.

If I will save above command in bat file and run this will generate list all services somehow ignoring WHERE statement. Running this as Administrator not changing anything.

1

There are 1 answers

0
rojo On BEST ANSWER

In a batch script you have to double pump the % signs so they'll be treated as literal percent signs. Change your command to this and it'll work:

wmic /OUTPUT:C:\LogServices.txt service where "not PathName like '%%Windows%%'" get DisplayName,Name,PathName,State,StartMode