Search code examples
windowsbatch-filewmic

Why does this wmic command not work in a batch file


I have a set of programs that i need to install, uninstall etc through batch files. So my batch file containst this line

wmic product where name="ABCcorp Tool" get version

Works fine, except for this tool

wmic product where name="XYZ® Tool" get version

It just prints

No Instance(s) Available.

Works perfectly if I run the same through the command line directly(administrator run)

Suspecting the Registered sign to be the culprit I changed it to

wmic product where "Name like 'XYZ%'" get version

Same problem: Runs directly on Command line but not through batch file. What should I do here?


Solution

  • This is more of a workaround than a solution. I figured out how to get the "Name like" correctly. Basically, it should be

    wmic product where "Name like 'XYZ%%'" get version
    

    inside a Batch file becuase % is a special character that needs to be escaped.

    So my problem is solved, but in case someone knows how to do it with the "®" sign, it may be useful for others.