Search code examples
windowsbatch-filecmdformattingwmic

Formating output from bat file


wmic product get name,version > "C:\myInformation.txt"
ECHO.  >> "C:\myInformation.txt"
ECHO %username% >> "C:\myInformation.txt"

I'm trying to write a batch file that will generate the software installed on the users computer as well as get their username for id purposes. The code above works individually. However, when I try to write out to the file, I get †਍敨瑣牯洮牡楴敮⁺਍ instead of "john.doe"

My question is, how can I get the software dump from wmic followed by the username without it spitting out garbage. I've flipped the order of commands. Doing so results in getting the username but not the software, in a neat output any ways.

Creating two files is not really something I want to do. I'd like one file per user.

Thanks in advance.


Solution

  • Use /APPEND:"myfile.txt" to output wmic in a file.
    i.e.

    echo. >"c:\myinformation.txt"
    wmic /APPEND:"c:\myinformation.txt" product get name,version >nul
    echo.  >> "c:\myinformation.txt"
    echo %username% >> "c:\myinformation.txt"