none
collect input and put into WMIC command RRS feed

  • Question

  • So I am trying to make a mini program/script for the end user, me at this point, to input a computer name and get the results of the software that computer has on it.

    I can do all of this in command prompt manually, however it looks like I lose the option if I put it in visual basic and add prompts.

    Here is the code I am working with.

    'Collect Computer Name
    ComputerNode = InputBox( "Enter Computer Name:" )
    Wscript.Echo ComputerNode
    Set objShell = CreateObject("WScript.Shell")
    'Get Software List
    objShell.run "wmic /OUTPUT:c:\software.txt /node: ComputerNode product get name,version,vendor"
    WScript.sleep 30000
    objShell.run "c:\software.txt" 
    SoftwareNode = InputBox( "Enter Software Name:" )
    objShell.run "cmd /K wmic /node: ""ComputerNode"" product where name=""SoftwareNode"" call uninstall"

    The issue appears that the wmic command is not translating the ComputerNode and SoftwareNode text for the objects they should represent. 

    Does anyone know if this is even possible this way? I am open to other options, like powershell. I just know more about vbs, which still isn't much.

    Wednesday, August 6, 2014 6:50 PM

Answers

  • Like this:

    objShell.run "wmic /OUTPUT:c:\software.txt /node:" & ComputerNode & " product get name,version,vendor"

    The same with the other line.

    Start here: http://technet.microsoft.com/en-us/scriptcenter/dd772284


    ¯\_(ツ)_/¯

    • Proposed as answer by jrv Wednesday, August 6, 2014 7:16 PM
    • Marked as answer by JCrescenzo Wednesday, August 6, 2014 7:53 PM
    Wednesday, August 6, 2014 7:16 PM
  • Hi,

    Here's a beginning if you'd like to move to PowerShell:

    $computerName = Read-Host 'Enter computer name'
    
    Get-WmiObject Win32_Product -ComputerName $computerName | 
        Select Name,Version,Vendor |
            Sort Name |
                Export-Csv ".\$computerName.csv" -NoTypeInformation
    
    & ".\$computerName.csv"
    
    $softwareToRemove = Read-Host 'Exact name of product to remove'
    
    (Get-WmiObject Win32_Product -Filter "Name = '$softwareToRemove'" -ComputerName $computerName).Uninstall()

    This will blow up if you give it bad data or anything at all goes wrong.


    Don't retire TechNet! - (Don't give up yet - 12,950+ strong and growing)

    • Marked as answer by JCrescenzo Wednesday, August 6, 2014 7:53 PM
    Wednesday, August 6, 2014 7:38 PM

All replies