首页 > 解决方案 > 按供应商搜索软件到 CSV 文件的批处理脚本

问题描述

我想要一个批处理脚本来搜索特定供应商在计算机上的软件并将结果保存到 CSV 文件....我尝试使用以下脚本,但它总是返回 NULL 值,无法弄清楚问题。

@echo off
Set "serial="
For /F "Skip=1 Delims=" %%A In ('WMIC BIOS Get SerialNumber') Do If Not Defined serial Call :Sub %%A
Set serial 2>Nul
:Sub
Set "serial=%*"
Set "LogFile=%serial%.CSV"

If Exist "%LogFile%" Del "%LogFile%"
wmic /Append:"%LogFile%" product where "Name like '%Microsoft%'" get Name, Version /Format:CSV

Start "" "%LogFile%"
exit

标签: batch-file

解决方案


注意: %需要用作通配符

在这种情况下,您应该添加另一个百分比字符%%Microsfot%逃避WMIC批次中的通配符并变得像%%Microsoft%%


@echo off
Title Batch Script to Search for Softwares by Vendor to a CSV file
Set "serial="
For /F "Skip=1 Delims=" %%A In ('WMIC BIOS Get SerialNumber') Do If Not Defined serial Call :Sub %%A
Set serial 2>Nul

:Sub
echo(
echo(    Please wait a while ... Searching for installed softwares ....
Set "serial=%*"
Set "LogFile=%serial%.CSV"
If Exist "%LogFile%" Del "%LogFile%"
wmic /Append:"%LogFile%" product where "Name like '%%Microsoft%%'" get Name, Version /Format:CSV
Start "" "%LogFile%"
Exit

推荐阅读