【问题标题】:WMIC Batch FileWMIC 批处理文件
【发布时间】:2015-08-17 23:11:23
【问题描述】:

我正在尝试使用 .bat 通过 WMIC 获取系统信息。我想在 C:\ 中使用计算机名称创建一个文件夹,然后在该文件夹中创建一些带有我正在寻找的信息的 .txt 文件。这是我目前所拥有的:

start cmd
cd C:\
md C:\%computername%_Software_Baseline
wmic 
/output:C:\%computername%_Software_Baseline\Installed_Software.txt product get name,version

这是我的第一个障碍。我收到文件名无效的消息。接下来的几个是我想在那个文件夹中创建的其他 .txt 文件(一旦我可以做第一个,我应该也可以将它应用到这些文件中)。

/output:C:\%computername%_Software_Baseline\Computer_System_Information.txt computersystem get domain,manufacturer,model,name,totalphysicalmemory
/output:C:\%computername%_Software_Baseline\Disk_Drive_Information.txt diskdrive get model,size,manufacturer
/output:C:\%computername%_Software_Baseline\CPU_Information.txt cpu get architecture,currentclockspeed,description,extclock,l2chachesize,manufacturer,name
/output:C:\%computername%_Software_Baseline\BIOS_Information.txt BIOS get serial number,name,smbiosbiosversion,manufacturer
/output:C:\%computername%_Software_Baseline\OS_Information.txt OS get name,cdsversion,manufacturer,freephysicalmemory,buildnumber

我还希望这也能将所有内容保存到我的网络上的一个文件夹中,但这可以等到我开始执行脚本。

【问题讨论】:

    标签: batch-file cmd wmic


    【解决方案1】:

    我不明白为什么不在当前cmd 实例中执行任务而省略start cmd

    @ECHO OFF
    SETLOCAL enableextensions
    
    md "C:\%computername%_Software_Baseline"
    wmic /output:"C:\%computername%_Software_Baseline\Installed_Software.txt" product get name,version
    

    或使用pushd - popd 命令对:

    @ECHO OFF
    SETLOCAL enableextensions
    
    md "C:\%computername%_Software_Baseline" 2>NUL
    
    pushd "C:\%computername%_Software_Baseline"
    wmic /output:"Installed_Software.txt" product get name,version
         rem further wmic commands here
    popd
    

    当指定 UNC 路径时,PUSHD 将创建一个临时驱动器 映射,然后将使用该新驱动器。临时驱动器号是 按字母倒序分配,所以如果Z: 是免费的,它将是 首先使用。

    POPD 还将删除由PUSHD 创建的任何临时驱动器映射。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多