bat脚本---盘点电脑硬件信息收集
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | '========================================================================== ' ' Date:2009/3/19 ' Name: 查询软件和硬件列表清单 ' Comment: blogs.itecn.net/smileruner ' Author:Smileruner ' www.overmcse.com ' 不支持Win2000及WinNT ' ' 3/19,添加了网卡过滤。 '========================================================================== 'on error resume Next const HKEY_LOCAL_MACHINE = &H80000002 const UNINSTALL_ROOT = "Software\Microsoft\Windows\CurrentVersion\Uninstall" const REG_SZ = 1 '========================================================================== 'Set wshshell=wscript.createobject("wscript.shell") ' wshshell.run ("%comspec% /c regsvr32 /s scrrun.dll"),0,true ' wshshell.run ("%comspec% /c sc config winmgmt start= auto"),0,true ' wshshell.run ("%comspec% /c net start winmgmt"),0 strIPPattern = "((2[0-4]\d|25[0-5]|1?\d\d?)\.){3}(2[0-4]\d|25[0-5]|1?\d\d?)" Set objNet = createobject( "Wscript.Network" ) Set objRegExp = New RegExp objregexp.Pattern = strIPPattern Set objWMIService = GetObject( "winmgmts:\\.\root\cimv2" ) Set IPConfigSet = objWMIService.ExecQuery _ ( "Select * from Win32_NetworkAdapterConfiguration Where IPEnabled=TRUE" ) For Each IPConfig in IPConfigSet If Not IsNull(IPConfig.IPAddress) Then For i=LBound(IPConfig.IPAddress) to UBound(IPConfig.IPAddress) If InStr(IPConfig.Caption(i), "VMware" ) = 0 And InStr(IPConfig.Caption(i), "Microsoft" ) = 0 Then If InStr(IPConfig.Caption(i), "169.254" ) = 0 And InStr(IPConfig.Caption(i), "0.0.0.0" ) = 0 Then If objregexp.Test(IPConfig.IPAddress(i)) = True Then strIP = IPConfig.IPAddress(i) End If End If End If Next End If Next strUser = objnet.UserName Set objNetwork = CreateObject( "WScript.Network" ) '========================================================================== strComputer = objNetwork.ComputerName If strComputer = "" then Wscript.Echo "未输入值或用户取消,查询退出。" Wscript.Quit End If Set objswbemlocator = createobject( "wbemscripting.swbemlocator" ) Set objswbemservices = objswbemlocator.connectserver(strComputer, "root\cimv2" ) If Err.number <> 0 then Wscript.Echo "目标计算机无法连接。错误的计算机名,或目标计算机启用了防火墙,RPC服务不可用。" Err.number.clear Wscript.Quit End If 'swbemservices.security_.impersonationleobjvel = 3 Set fso=createobject( "scripting.filesystemobject" ) FileDate = Replace(date(), "/" , "-" ) resoultfilepath= strComputer & "_" & FileDate & ".html" Set resultFile= fso.createtextfile(resoultfilepath,,true) HtmlWriteHead() 'Html文档开始 TableHead strComputer, "硬件清单" 'Html表格开始 OsWrite() '写入操作系统信息 BoardWrite() '写入主板信息 CpuWrite() '写入CPU信息 MemoryWrite() '写入内存信息 HarddiskWrite() '写入硬盘信息 CdromWrite() '写入CDROM信息 VideoWrite() '写入显示卡信息 NetcardWrite() '写入网卡信息 TableEnd() 'Html表格结尾 TableHead strComputer, "软件清单" 'Html表格开头 Softlist() '写入软件信息 TableEnd() 'Html表格结尾 HtmlWriteEnd() 'Html文档结束 ResultFile.close Wscript.Echo "查询完成!" '=========以下是函数列表========== Function OsWrite() '函数,写入操作系统信息 Set colOs =objswbemservices.execquery( "select * from win32_operatingsystem" ,,48) For Each Ositem In colOs oscaption = Ositem.caption OsVersion = oscaption & Ositem.version WriteTable "操作系统" ,OsVersion Next End Function Function BoardWrite() '函数,写入主板信息 Set colBoard = objswbemservices.execquery( "select * from win32_baseboard" ) For Each Bditem In colBoard boardname = Bditem.product WriteTable "主板" ,boardname Next End Function Function CpuWrite() '函数,写入CPU信息 Set colCpu =objswbemservices.execquery( "select * from win32_processor" ) For Each item in colCpu cpuname = (trim(item.name)) WriteTable "中央处理器" ,cpuname Next End Function Function MemoryWrite() '函数,写入内存信息 mtotal = 0 num = 0 mill = 0 Set colMemory = objswbemservices.execquery( "select * from win32_physicalmemory" ,,48) For Each objitem In colMemory mill = objitem.capacity/1048576 WriteTable "单根内存容量" ,mill & "M" mtotal = mtotal+mill num = num + 1 Next WriteTable "总计内存" ,num & "条" & "一共" & mtotal & "M" End Function Function HarddiskWrite() '函数,写入硬盘信息 Set colDisk = objswbemservices.execquery( "select * from win32_diskdrive" , , 48) For Each objitem In colDisk diskname= objitem.caption disksize= fix(objitem.size/1073741824) disknumber= objitem.size WriteTable "硬盘" ,diskname & " 容量:" & disksize & "G" Next End Function Function CdromWrite() '函数,写入CDROM信息 Set colCdrom = objswbemservices.execquery( "select * from win32_cdromdrive where scsitargetid=0" ) For Each objitem In colCdrom cdname = objitem.name WriteTable "光驱" ,cdname Next End Function Function videoWrite() '函数,写入显示卡信息 Set colVideo = objswbemservices.execquery( "select * from win32_videocontroller" , , 48) For Each objitem in colVideo videoname = (trim(objitem.caption) & (objitem.videomodedescription)) WriteTable "显示卡" ,videoname Next End Function Function netcardWrite() '函数,查询网卡信息 Set colNetcards = objswbemservices.execquery( "select * from win32_networkadapter" ) For Each objNetcard in colNetcards If Not IsNull(objNetcard.NetConnectionID) Then NetCardName = objNetcard.productname WriteTable "网卡名称" ,NetCardName If objNetcard.NetConnectionStatus = 2 Then NetCardMac = objNetcard.macaddress WriteTable "网卡Mac" ,NetCardMac strQueryIp = "select * from win32_networkadapterconfiguration" &_ " where IPEnabled = true" &_ " and macaddress = '" & objNetcard.macaddress & "'" Set colNetcardCfgs = objswbemservices.execquery(strQueryIp) For Each objNetcardCfg in colNetcardCfgs For Each CfgAdrress in objNetcardCfg.IPAddress IpAdrress = CfgAdrress WriteTable "IP地址" ,IpAdrress Next Next Else NetCardMac = "网卡被禁用或未连接。" WriteTable "网卡Mac" ,NetCardMac IpAdrress = "网卡被禁用或未连接。" WriteTable "IP地址" ,IpAdrress End If End if Next End Function Function softlist() '函数,写入软件信息 Set StdOut = WScript.StdOut Set oReg=GetObject( "winmgmts:{impersonationLevel=impersonate}!\\" &_ strComputer & "\root\default:StdRegProv" ) strKeyPath = UNINSTALL_ROOT oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys For Each strSubKey In arrSubKeys If NotHotfix(strSubKey) Then SoftNameAndVersion = getProgNameAndVersion(oReg,strKeyPath & "\" & strSubKey) If SoftNameAndVersion<> "0" Then WriteTable "软件" ,SoftNameAndVersion End If End If Next End Function Function NotHotfix(sSubKey) If Left(sSubkey,2) = "KB" And len(sSubkey) = 8 Then NotHotfix = 0 Else NotHotfix = 1 End if End Function Function getProgNameAndVersion(oReg,sKeyRoot) Dim sKeyValuesAry, iKeyTypesAry, nCnt, sValue, sDisplayName, sDisplayVersion oReg.EnumValues HKEY_LOCAL_MACHINE, sKeyRoot, sKeyValuesAry, iKeyTypesAry If NOT IsArray(sKeyValuesAry) Then getProgNameAndVersion = 0 Exit Function End If For nCnt = 0 To UBound(sKeyValuesAry) If InStr(1, sKeyValuesAry(nCnt), "DisplayName" , vbTextCompare) Then If iKeyTypesAry(nCnt) = REG_SZ Then oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyRoot, sKeyValuesAry(nCnt), sValue If sValue<> "" Then sDisplayName = sValue sDisplayName = Replace(sDisplayName, "[" , "(" ) sDisplayName = Replace(sDisplayName, "]" , ")" ) End If End If ElseIf InStr(1, sKeyValuesAry(nCnt), "DisplayVersion" , vbTextCompare) Then If iKeyTypesAry(nCnt) = REG_SZ Then oReg.GetStringValue HKEY_LOCAL_MACHINE, sKeyRoot, sKeyValuesAry(nCnt), sValue If sValue<> "" Then sDisplayVersion = sValue End If End If If (sDisplayName<> "" ) AND (sDisplayVersion<> "" ) Then getProgNameAndVersion = sDisplayName & " --版本号: " & sDisplayVersion Exit Function Else getProgNameAndVersion = 0 End If Next If sDisplayName<> "" Then getProgNameAndVersion = sDisplayName Exit Function End If End Function Function WriteTable(caption,value) '函数,将数据写入HTML单元格 resultFile.Writeline "<tr>" resultFile.Writeline "<td align=" "left" " width=" "30%" " height=" "25" " bgcolor=" "#ffffff" " scope=" "row" "> " & caption & "</td>" resultFile.Writeline "<td bgcolor=" "#ffffff" "> " & value & "</td>" resultFile.Writeline "</tr>" End Function Function HtmlWriteHead() '函数,写入THML文件头 resultFile.Writeline "<html>" resultFile.Writeline "<head>" resultFile.Writeline "<title>软硬件配置清单</title>" resultFile.Writeline "</head>" resultFile.Writeline "<body>" End Function Function HtmlWriteEnd() '函数,写入Html文件尾 resultFile.Writeline "</body>" resultFile.Writeline "</html>" End Function Function TableHead(pcname,str) '函数,写入Html表格结尾 resultFile.Writeline "<h3>" & pcname & str & " -- date:" &now()& " </h3>" & VbCrLf resultFile.Writeline "<table width=" "90%" " border=" "0" " align=" "center" " cellpadding=" "0" " cellspacing=" "1" " bgcolor=" "#0000ff" ">" resultFile.Writeline "<tr>" resultFile.Writeline "<th width=" "30%" " height=" "25" " bgcolor=" "#ffffff" " scope=" "col" ">资产类型</th>" resultFile.Writeline "<th bgcolor=" "#ffffff" " scope=" "col" ">查询结果值</th>" resultFile.Writeline "</tr>" strstyle = "<th width=" "30%" " height=" "25" " bgcolor=" "#ffffff" " scope=" "row" ">" End Function Function TableEnd() '函数,Html表格结尾 resultFile.Writeline "</table>" End Function |
title 收集信息
@echo off
@echo Now initializing the program,please wait a minite···
for /F %%i in ('echo %USERNAME%-%date:~0,4%%date:~5,2%%date:~8,2%%time:~3,2%%time:~6,2%') do ( set filename=%%i)
md %filename%
cd ./%filename%
echo %date% %time% >>硬件SN信息.txt
echo ###电脑名称###>>硬件SN信息.txt
hostname>>硬件SN信息.txt
echo ###用户名称###>>硬件SN信息.txt
echo %username% >>硬件SN信息.txt
echo ### 安装系统时间 ### >>硬件SN信息.txt
wmic os get installdate >>硬件SN信息.txt
echo ### 电脑型号 ### >>硬件SN信息.txt
wmic csproduct get name>>硬件SN信息.txt
echo ### 电脑品牌 ### >>硬件SN信息.txt
wmic BASEBOARD get Manufacturer >>硬件SN信息.txt
echo ### 发行日期 ### >>硬件SN信息.txt
wmic bios get ReleaseDate>>硬件SN信息.txt
echo ### 主板SN信息 ### >> 硬件SN信息.txt
wmic baseboard get serialnumber >>硬件SN信息.txt
echo ### 内存SN信息 ### >> 硬件SN信息.txt
wmic memorychip get PartNumber, SerialNumber>>硬件SN信息.txt
echo ### 硬盘SN信息 ### >>硬件SN信息.txt
wmic diskdrive get Caption,size,InterfaceType,serialnumber >>硬件SN信息.txt
pause
exit
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现