Windows Batch System Info to HTML

安稳与你 提交于 2019-11-28 12:57:41

It all depends on how fancy you want to get. The simplest way would be

@echo off
(
echo ^<HTML^> 
echo ^<BODY^> 
echo ^<pre^> 
systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"OS Manufacturer" /C:"OS Configuration" /C:"OS Build Type" /C:"Original Install Date" /C:"System Boot Time" /C:"System Manufacturer" /C:"System Model" /C:"System Type" /C:"Processor(s)" /C:"BIOS Version" /C:"Windows Directory" /C:"System Directory" /C:"Boot Device" /C:"System Locale" /C:"Input Locale" /C:"Total Physical Memory" /C:"Available Physical Memory" /C:"Virtual Memory: Max Size" /C:"Virtual Memory: Available" /C:"Virtual Memory: In Use" /C:"Domain" /C:"Network Card(s)"
echo ^</pre^> 
echo ^</BODY^> 
echo ^</HTML^>
)>sysinfo.html

And here is a way with a CSS formatted table

@echo off
systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"OS Manufacturer" /C:"OS Configuration" /C:"OS Build Type" /C:"Original Install Date" /C:"System Boot Time" /C:"System Manufacturer" /C:"System Model" /C:"System Type" /C:"Processor(s)" /C:"BIOS Version" /C:"Windows Directory" /C:"System Directory" /C:"Boot Device" /C:"System Locale" /C:"Input Locale" /C:"Total Physical Memory" /C:"Available Physical Memory" /C:"Virtual Memory: Max Size" /C:"Virtual Memory: Available" /C:"Virtual Memory: In Use" /C:"Domain" /C:"Network Card(s)">temp.txt
if exist systeminfo.html del /f /q systeminfo.html
call :CreateHTMLtable temp.txt systeminfo.html
if exist temp.txt del /f /q temp.txt
exit /b

:CreateHTMLTable <inputfile> <outputfile>
setlocal
>%2 echo ^<!DOCTYPE HTML PUBLIC 
>>%2 echo "-//W3C//DTD HTML 4.01 Transitional//EN"
>>%2 echo  "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"^>
>>%2 echo ^<HTML^>
>>%2 echo ^<HEAD^>
>>%2 echo ^<META HTTP-EQUIV="Content-Type" 
>>%2 echo CONTENT="text/html; charset=utf-8"^>
>>%2 echo ^</HEAD^>
>>%2 echo ^<BODY^>
>>%2 echo ^<style type="text/css"^>
>>%2 echo .tftable {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #bcaf91;border-collapse: collapse;}
>>%2 echo .tftable th {font-size:12px;background-color:#ded0b0;border-width: 1px;padding: 8px;border-style: solid;border-color: #bcaf91;text-align:left;}
>>%2 echo .tftable tr {background-color:#e9dbbb;}
>>%2 echo .tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #bcaf91;}
>>%2 echo .tftable tr:hover {background-color:#ffffff;}
>>%2 echo ^</style^>
>>%2 echo ^<table class="tftable" border="1"^>
for /f "tokens=1,2 delims=:" %%a in (%1) do (
>>%2 echo ^<tr^>^<td^>%%a^</td^>^<td^>%%b^</td^>^</tr^>
)
>>%2 echo ^</table^>
>>%2 echo ^</BODY^>
>>%2 echo ^</HTML^>
unclemeat

The following should work for you. Happy to provide any explanation.

@echo off
(
echo ^<table^>
systeminfo | findstr /B /C:"OS Name" /C:"OS Version" /C:"OS Manufacturer" /C:"OS Configuration" /C:"OS Build Type" /C:"Original Install Date" /C:"System Boot Time" /C:"System Manufacturer" /C:"System Model" /C:"System Type" /C:"Processor(s)" /C:"BIOS Version" /C:"Windows Directory" /C:"System Directory" /C:"Boot Device" /C:"System Locale" /C:"Input Locale" /C:"Total Physical Memory" /C:"Available Physical Memory" /C:"Virtual Memory: Max Size" /C:"Virtual Memory: Available" /C:"Virtual Memory: In Use" /C:"Domain" /C:"Network Card(s)">f.txt
for /f "tokens=1* delims=:" %%a in (f.txt) do echo ^<tr^>^<td^>%%a^</td^> ^<td^>%%b^</td^>^</tr^>
echo ^</table^>
) >test.html

Obviously change the >>test.html to be the name of whatever file you want to output to, I suggest a variable might be best. You also might want to delete f.txt at the end of the script. You can style it by echoing whatever CSS to (I've used) test.html.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!