Search code examples
windowscommand-promptwmic

No Instance(s) Found when remotely getting a list of installed programs


When I run my batch file, I'll type in the computer's name, then type the name of the program I'm looking for. I have added the "name like '(word)%'" part so it doesn't need an exact match to find a program. Here is my code:

@echo off
set /p name="Enter PC Name: "
set /p prgm="Type Part of the Program Name: "
wmic /node:%name% product where "name like '%prgm%%'" get name,version
set /p fprgm="Enter Full Program Name: "
wmic /node:%name% product where name="%fprgm%" call uninstall
pause

If I go into WMIC manually and search using the /node:(pc-name) product where "name like '(word)%'" get name,version it works. But running the code above does not; instead it returns

No Instance(s) Found


Solution

  • You need to escape some characters with special meaning so they are interpreted literally.

    To treat a percent sign (%) as a regular character in a batch script, double it (%%) as in next example:

    ==>type 29951224.bat
    @ECHO ON >NUL
    @SETLOCAL
    
    set "name=localhost"
    set "prgm=visual F"
    wmic /node:%name% product where "name like '%prgm%%%'" get name,version
    
    ==>29951224.bat
    
    ==>set "name=localhost"
    ==>set "prgm=visual F"
    ==>wmic /node:localhost product where "name like 'visual F%'" get name,version
    Name               Version
    Visual F# 3.1 SDK  12.0.21005
    Visual F# 3.1 VS   12.0.21005
    
    ==>