努力寻找所需的答案/代码。
目前使用以下脚本。我希望文本输出文件是主机名。
我该怎么做?
@echo off
REM setlocal enabledelayedexpansion
(
systeminfo | findstr /c:"Host Name"
systeminfo | findstr /c:"Domain"
systeminfo | findstr /c:"OS Name"
systeminfo | findstr /c:"OS Version"
systeminfo | findstr /c:"System Manufacturer"
systeminfo | findstr /c:"System Model"
systeminfo | findstr /c:"System type"
systeminfo | findstr /c:"Total Physical Memory"
ipconfig | findstr IPv4
echo.
echo Hard Drive Space:
wmic diskdrive get size
echo.
echo.
echo Service Tag:
wmic bios get serialnumber
echo.
echo.
echo CPU:
wmic cpu get name
) > "%~dpn0.txt"
答案 0 :(得分:0)
刚从新手那里得到一些猜测......
一个。我看到你正在调用Windows systeminfo.exe来返回你的数据。 您是否可以调用第三方应用程序(如Piriform的Speccy)来返回您想要的数据? a)www_piriform_com / speccy, b)technet_microsoft_com / en-au / library / bb491007.aspx
B中。看起来你从这里得到你的代码 - https://community.spiceworks.com/how_to/63832-get-the-computer-name-ip-address-and-others-with-this-batch-file
上述文章中“alinlupascu”的答案可能有助于减少systeminfo.exe响应的等待时间。另请参阅“joeyalbanese”的答案 - 将信息发送到文本文件。
上面的Spiceworks文章中的代码不使用延迟扩展,也许它不是必需的?
℃。这似乎没有提供任何新信息,但你可以从这里收集一些东西 - http://www.windows-commandline.com/system-information-systeminfo-command/
答案 1 :(得分:0)
只需将最后一行%~dpn0.txt
更改为%ComputerName%.txt
@echo off
REM setlocal enabledelayedexpansion
(
systeminfo | findstr /c:"Host Name"
systeminfo | findstr /c:"Domain"
systeminfo | findstr /c:"OS Name"
systeminfo | findstr /c:"OS Version"
systeminfo | findstr /c:"System Manufacturer"
systeminfo | findstr /c:"System Model"
systeminfo | findstr /c:"System type"
systeminfo | findstr /c:"Total Physical Memory"
ipconfig | findstr IPv4
echo.
echo Hard Drive Space:
wmic diskdrive get size
echo.
echo.
echo Service Tag:
wmic bios get serialnumber
echo.
echo.
echo CPU:
wmic cpu get name
) > "%ComputerName%.txt"
答案 2 :(得分:0)
这与间距一样干净,但在PowerShell中做了你想做的事情:
$content = systeminfo | Select-String -Pattern "Host Name","Domain","OS Name","OS Version","System Manufacturer","System Model","System type","Total Physical Memory"
$content += "`n`nHard Drive Space:"
$content += wmic diskdrive get size
$content += "`n`nService Tag:"
$content += wmic bios get serialnumber
$content += "`n`nCPU:"
$content += wmic cpu get name
$outfile = $env:computername + ".txt"
$content | Out-File $outfile -Encoding ASCII