再发 用脚本自动检测硬件信息and生成EXCEL
''''''''''''''说明''''''''''''
% Y* t( ]+ A+ `2 v. c$ _" K) d'菊花-mfknui制作,送给需要的朋友。- l. K2 B; Q) M5 \+ e% P
) T! p- ?' j* v2 P/ P* i
'本脚本的功能是检测硬件的信息。
8 H, Q$ O2 J3 N+ wOn Error Resume Next
+ K% }2 n( p3 ^6 s P+ i3 S6 d6 m; _temp=0
4 M+ {$ v" e, k2 r2 D+ h$ [6 tset wshshell=wscript.createobject("wscript.shell")
' Y) `! m6 H& H2 R7 N'启动WMI服务
# i3 b6 H! q; s0 T( `wshshell.run ("%comspec% /c regsvr32 /s scrrun.dll"),0,True& S i4 ^, ?7 [. S2 w, e
wshshell.run ("%comspec% /c sc config winmgmt start= auto"),0,True* h* v5 E* Q4 A$ m+ w
wshshell.run ("%comspec% /c net start winmgmt"),00 g# Z+ s/ ?3 p( t9 I$ J
'用一个文本来记录硬件信息
0 O! Q' C( {4 L: ~- ^% _7 k3 b0 A& iSet WshNetwork = WScript.Createobject("WScript.Network")
/ q0 g" e; n& z' L5 F, qcomputername=WshNetwork.ComputerName
- ]* S* A/ k5 N! ~set fso=createobject("scripting.filesystemobject"), t7 s& J- F' _# F; s! \
tempfilter="[url=file://\\192.168.1.18\]\\192.168.1.18\[/url]上传资料\"& computername &".txt", L9 A( X: Y; ^/ \
'\\192.168.1.18\上传资料\
6 D" Z, D q* x* m. ?set tempfile=fso.createtextfile(tempfilter)$ V: x# m: a0 ]2 m1 I
strComputer = "."6 w3 [' x) y' b4 i! B
Set objWMIService = Getobject("winmgmts:\\" & strComputer & "\root\cimv2")
" v- p. J# D9 z! b& E: Z# d'主板# O% F. _) D5 I- i
set board =objwmiservice.execQuery("select * from win32_baseboard")
% Y" B# X: @- Z) @" i. [for each item in board* U8 u P X) I; `3 M
board2="主板:" & item.Product
3 X. X3 S* R- s& z+ x! knext
1 D6 b- v1 u9 ?# m! V. T# N'CPU
7 R- T' G3 J; c9 \- O) p: I1 Jset cpu =objwmiservice.execQuery("select * from win32_processor")6 G) X6 `3 O- o4 |9 r
for each item in cpu$ Q* Q' p* d- G/ A+ u. ]5 p' N" n
cpu2= "CPU:" & item.Name
X* i' u, K5 mnext
$ M0 C; h4 C: w. K$ Z8 l, G, R'内存
" p$ T$ Q$ Z1 ?6 z2 t+ KSet colItems = objWMIService.ExecQuery("Select * from Win32_PhysicalMemory",,48)
4 W3 L0 [! \/ zFor Each objItem in colItems
$ ^: f& ]6 a* f( Y( j( q9 ~a=objitem.capacity/10485761 S' p0 u: z- `( x9 L/ D& d2 ?
temp=temp+objitem.capacity% K! c# t9 d+ B( }- M
n=n+1
) S- Y9 {7 |+ i5 [Next" D0 B, W/ f2 E' J. Q. e4 ^4 }
memory=temp/1048576, w( ~/ y) a7 y- N
if n=1 then
0 ]" l8 N& Y! F0 J" F4 @0 s6 i* Omemory2= "内存: " & n & "条" &a&"M"$ W# ^* ~! K) Z% L; k
else7 y, c* |+ w9 \/ K
memory2= "内存: " & n & "条" &a&"M"&" 总计"&memory&"M"
) k. Y. z5 @ Fend if
* n4 e3 B$ G& z4 I( ^'硬盘6 f8 E6 l# U# g. T4 Y/ ` w
set disk =objwmiservice.execQuery("select * from win32_diskdrive")7 X! [+ e, T0 E# ^7 R
for each item in disk% y# [8 D9 N w, U8 d; `- P
disk2= "硬盘: " & item.Model6 s# L" J3 a: ] N7 m) A
next
) `) v2 }# e8 J$ L'显卡& C( ]& P: q3 F5 J
set video =objwmiservice.execQuery("select * from win32_videocontroller",,48)+ ?% _3 B! J/ p
for each item in video0 p' v6 P! h( N4 T
video2= "显卡: " & item.Description# o; B3 y# P% s. v, E2 K" P3 c& ^( i
next
/ j9 Z# _. x/ v! R. x/ P'网卡
) ~8 I- G2 e+ m% {& x, aSet colItems = objWMIService.ExecQuery("Select * from Win32_NetworkAdapter",,48)
; Y! s5 v/ g: t) _- Y! GFor Each objItem in colItems. w' t6 Q/ t" C( }
if (left(objItem.NetConnectionID,4)="本地连接") then
) j' k; }$ P, {lanname=objItem.Name 2 o8 \7 P; u( }' e7 _0 L
end if
0 h) y) F M/ L/ F' yNext# f" t- _7 ^: |5 U
lan2="网卡: " & lanname8 T/ q+ j4 d2 ^! S% ?) K7 E
tempfile.writeline(board2)
) y9 m, U$ b4 l" z* f* V: [; h! ]tempfile.writeline(cpu2)
# u5 ^5 c0 A* d; d$ D& ?tempfile.writeline(memory2)0 A0 s+ R C# G
tempfile.writeline(disk2)
& g( K- A, z5 L6 \/ ttempfile.writeline(video2)5 e9 l: r9 |1 A9 T
tempfile.writeline(lan2)
}# M# T; n# `* T& c' m6 x9 m
: f( A [% l, n3 n; F
, `3 R" ~& S* R. v! F6 H& _6 {: B! j# G* T1 k
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/ p1 V8 T+ L3 ~8 o6 T以下是自动生成EXCEL的脚本5 K7 Y: I* ]# j2 M: e( n& X
$ \ N* |# F' G7 y: j$ A# S) B# |
6 O% R& {1 \0 H5 E2 U
Const forwriting=2
b" b* P! h+ T" |Const forreading=1
+ g' X& O+ A4 m( ]7 X7 xDim oFSO,oF,r1,s# `9 O- ^$ `: \& P" o
Set oFSO = CreateObject("Scripting.FileSystemObject") v% M4 _+ W4 z1 I2 v! G* h
Set oShell = WScript.CreateObject("WScript.Shell")
7 J- n) ?; m. U$ z) ~; toshell.run ("%comspec% /c if exist c:\temp.txt del /q c:\temp.txt"),0,True
% V. U% l U3 Poshell.run ("%comspec% /c if exist c:\excel.csv del /q c:\excel.csv"),0,True. b5 K8 z: O! s+ Z1 J. T' r7 k1 Q
oshell.run("%comspec% /c dir /b/o:n *.txt >>c:\temp.txt"),0,True s6 a! k) O$ i2 y* h/ n( C
X: N3 B( @7 g; ^8 o4 ISet oF = oFSO.CreateTextFile("c:\excel.csv")3 q9 t5 H6 J/ Q0 f# u
of.writeline "机号,主板,CPU,内存,硬盘,显卡,网卡"
/ e! `% i8 B1 e' _; `+ CSet objFSO1 = CreateObject("Scripting.FileSystemObject") A) T- E, |& L [
Set objTextFile1 = objFSO1.OpenTextFile _ ]: N& {- D/ y( u7 }! j0 Y( g
("c:\temp.txt", ForReading): r" P7 `: _- z* ~& j5 A- K1 K
objTextFile1.ReadAll0 J5 W6 c# F' y( a
line=objTextFile1.line' }, \3 Z# X9 \7 e) @' @5 y1 P
4 w5 P1 X' X, O* A- }for l=1 to line-1
8 }1 @& F" z+ |1 ESet objFSO = CreateObject("Scripting.FileSystemObject")
5 i- o5 l: {9 y5 c/ e0 {7 i$ BSet objTextFile = objFSO.OpenTextFile("c:\temp.txt", ForReading)& r# I& W2 }) c3 R, ?
For i=1 to l" V. I( Y% E' ^, M+ B, Z* J
r1=objTextFile.ReadLine8 @ T& I' S$ Q ^" y
next: |/ l6 W, K" [% A" ^' M
file=left(r1,len(r1)-4)&","# Z: `- W8 R" @$ Q
Set fso = CreateObject("Scripting.FileSystemObject")
6 V. Z: y: l0 g) K" I& nset f = fso.OpenTextFile(r1, Forreading)
( X+ o3 h. [ O( j, [/ ^for i=1 to 6& B9 h" j, `3 |; b/ r' S
f.skip(3)
: p5 b: r- y( ?$ R" `9 Kr=f.readline5 o7 e" w0 I, u. [' n* K
file=file & r &","* F3 b3 Y: \% ?6 q
next
* I# [, m% y9 [: J( K" O" Gof.writeline file5 }4 @9 ~9 \1 a& F3 W# S
next
, ?# n7 F0 P. X/ B/ t) P% \- Z: L2 }/ l% \( g9 ~- s* @8 J5 w7 C/ @% }- ]
oshell.run("c:\excel.csv"),0,True
搜索更多相关主题的帖子:
EXCEL 自动检测 脚本 硬件