1

这是我的代码。

@ECHO OFF
systeminfo > C:\SystemInfo1.txt

findstr /C:"OS Name:" /C:"OS Version:" /C:"OS Manufacturer:" /C:"Original Install Date:" /C:"System Boot Time:" /C:"System Manufacturer:" /C:"System Model:" /C:"System Type:" /C:"Processor(s):" /C:"System Locale:" /C:"Input Locale:" /C:"Time Zone:" /C:"NetWork Card"  C:\SystemInfo1.txt > c:\SystemInfo.txt

DEL C:\SystemInfo1.txt

c:\SystemInfo.txt
EXIT

如果您在显示网卡详细信息的末尾看到系统信息文件,则此代码的作用是仅显示我需要从文本文件“Systeminfo1.txt”中选择的内容。但是有了这段代码,我只得到第一行。

实际系统信息:

Host Name:                 BLRPN0W01085
OS Name:                   Microsoft Windows XP Professional
OS Version:                5.1.2600 Service Pack 3 Build 2600
OS Manufacturer:           Microsoft Corporation
OS Configuration:          Member Workstation
OS Build Type:             Uniprocessor Free
Registered Owner:          Admin
Registered Organization:   Thomson Reuters
Original Install Date:     8/31/2011, 10:46:03 AM
System Up Time:            0 Days, 10 Hours, 19 Minutes, 2 Seconds
System Manufacturer:       Dell Inc.
System Model:              OptiPlex 755                 
System type:               X86-based PC
Processor(s):              1 Processor(s) Installed.
                       [01]: x86 Family 6 Model 23 Stepping 6 GenuineIntel ~2992 Mhz
BIOS Version:              DELL   - 15
Windows Directory:         C:\WINDOWS
System Directory:          C:\WINDOWS\system32
Boot Device:               \Device\HarddiskVolume1
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Time Zone:                 (GMT) Casablanca
Total Physical Memory:     2,014 MB
Available Physical Memory: 772 MB
Virtual Memory: Max Size:  2,048 MB
Virtual Memory: Available: 2,008 MB
Virtual Memory: In Use:    40 MB
Page File Location(s):     C:\pagefile.sys
Domain:                    tfcorp.tfn.com
Logon Server:              \\INKABAN1DIR01
Hotfix(s):                 319 Hotfix(s) Installed.
                       [01]: File 1
                       [02]: File 1
                       [03]: File 1
                       [04]: File 1
                       [05]: File 1
                       [06]: File 1
                       [07]: File 1
                       [08]: File 1
                       [09]: File 1
                       [10]: File 1
                       [11]: File 1
                       [12]: File 1
                       [13]: File 1
                       [14]: File 1
                       [15]: File 1
                       [16]: File 1
                       [17]: File 1
                       [18]: File 1
                       [19]: File 1
                       [20]: File 1
                       [21]: File 1
                       [22]: File 1
                       [23]: File 1
                       [24]: File 1
                       [25]: File 1
                       [26]: File 1
                       [27]: File 1
                       [28]: File 1
                       [29]: File 1
                       [30]: File 1
                       [31]: File 1
                       [32]: File 1
                       [33]: File 1
                       [34]: File 1
                       [35]: File 1
                       [36]: File 1
                       [37]: File 1
                       [38]: File 1
                       [39]: File 1
                       [40]: File 1
                       [41]: File 1
                       [42]: File 1
                       [43]: File 1
                       [44]: File 1
                       [45]: File 1
                       [46]: File 1
                       [47]: File 1
                       [48]: File 1
                       [49]: File 1
                       [50]: File 1
                       [51]: File 1
                       [52]: File 1
                       [53]: File 1
                       [54]: File 1
                       [55]: File 1
                       [56]: File 1
                       [57]: File 1
                       [58]: File 1
                       [59]: File 1
                       [60]: File 1
                       [61]: File 1
                       [62]: File 1
                       [63]: File 1
                       [64]: File 1
                       [65]: File 1
                       [66]: File 1


NetWork Card(s):           1 NIC(s) Installed.
                        [01]: Intel(R) 82566DM-2 Gigabit Network Connection
                              Connection Name: Local Area Connection
                              DHCP Enabled:    Yes
                              DHCP Server:     10.136.193.51
                              IP address(es)
                              [01]: 10.136.208.125

我的代码显示的内容:

OS Name:                   Microsoft Windows XP Professional
OS Version:                5.1.2600 Service Pack 3 Build 2600
OS Manufacturer:           Microsoft Corporation
Original Install Date:     8/31/2011, 10:46:03 AM
System Manufacturer:       Dell Inc.
System Model:              OptiPlex 755                 
Processor(s):              1 Processor(s) Installed.
BIOS Version:              DELL   - 15
System Locale:             en-us;English (United States)
Input Locale:              en-us;English (United States)
Time Zone:                 (GMT) Casablanca
NetWork Card(s):           1 NIC(s) Installed.

什么不见​​了:

[01]: Intel(R) 82566DM-2 Gigabit Network Connection
                                 Connection Name: Local Area Connection
                                 DHCP Enabled:    Yes
                                 DHCP Server:     10.136.193.51
                                 IP address(es)
                                 [01]: 10.136.208.125

我如何得到缺少的东西?顺便说一句,有人知道为什么 BIOS 显示为“DELL - 15”吗?这仅适用于 XP。

4

3 回答 3

2

开始了:

@ECHO OFF
systeminfo >c:\SystemInfo1.txt

findstr /C:"OS Name:" /C:"OS Version:" /C:"OS Manufacturer:" /C:"Original Install Date:" /C:"System Boot Time:" /C:"System Manufacturer:" /C:"System Model:" /C:"System Type:" /C:"Processor(s):" /C:"System Locale:" /C:"Input Locale:" /C:"Time Zone:" /C:"NetWork Card" c:\SystemInfo1.txt >c:\SystemInfo.txt

for /f "tokens=1 delims=:" %%a in ('findstr /n "NetWork Card" c:\SystemInfo1.txt') do set line=%%a & goto remainder

:remainder
more +%line% c:\SystemInfo1.txt >>c:\SystemInfo.txt

DEL C:\SystemInfo1.txt
c:\SystemInfo.txt
EXIT /b

如果您确定只有一个 NIC(网卡),那么您可以从“FOR 语句”的末尾删除“ & goto remaining ”并删除标签“ :remainder ”。

于 2012-01-14T05:27:31.323 回答
1

只使用“findstr”是不可能做你想做的事的,因为你需要根据它们的上下文来选择行(即第一块网卡后面的缩进行)。使用 perl、awk、ruby 或其他脚本语言来完成它是微不足道的。

想到一种只用 Windows 东西做你想做的事情的方法,我想到了 Javascript。请注意,Javascript 不是我的强项,这可能会变得更好,但假设您想要“网络卡”之后的所有行,这应该可以工作:

把它放在一个文件中(例如:filter.js):

function processTextStream() {
    finder = new RegExp( "^((OS (Name|Version|Manufacturer))" +
                    "|(Original Install)|(System (Manuf|Model|Locale))" +
                    "|Processor|BIOS|Input Locale|Time Zone" +
                    ")" )
    netcard = new RegExp( "^NetWork Card" );

    printall = false;

    while (!WScript.StdIn.AtEndOfStream) {
        line = WScript.StdIn.ReadLine();
        if (finder.test(line))
        {
            WScript.echo(line);
        }
        else if (netcard.test(line))
        {
            WScript.echo(line);
            printall = true;
        }
        else if (printall)
        {
            WScript.echo(line);
        }

    }
}

// Main script flow
processTextStream();

从您的批处理文件中,执行:

systeminfo | cscript //nologo filter.js >SystemInfo.txt
于 2012-01-10T16:24:58.550 回答
0

字符串匹配仅限于一行(即回车之间的内容)。因此您需要将缺少的标识符添加到您的搜索字符串列表中。

systeminfo | findstr /C:"NetWork Card" /C:"[01]:" /C:"Connection Name:" /C:"DHCP Enabled:" /C:"DHCP Server:"

你会注意到这也会在你的处理器上带来额外的信息,因为 [01] 也在那里匹配。如果您认为一个盒子可能有多个网卡,您也可以搜索 [02]。

如果您只想在它存在时搜索它,那么您将需要使用第一次运行的 systeminfo 输出作为另一个搜索文件的输入。例如,第一次运行的输出会告诉你,1 NIC(s) Installed或者2 NIC(s) Installed你需要用for循环和字符匹配来解析它,以获得安装的 nics 的确切数量,然后使用它再次搜索 systeminfo。

于 2012-01-10T17:21:02.560 回答