用脚本自动检测硬件信息,再用脚本Excel输出
在网吧,由于我们老板经常叫我们查配件,所以有空就自己编了个脚本.
一直在用,没出什么问题.希望对有用的人有点帮助.
以下是VBS脚本的内容:
'本脚本的功能是检测硬件的信息。
OnErrorResumeNext temp=0 setwshshell=wscript.createobject("wscript.shell") '启动WMI服务 wshshell.run("%comspec%/cregsvr32/sscrrun.dll"),0,True wshshell.run("%comspec%/cscconfig winmgmtstart=auto"),0,True wshshell.run("%comspec%/cnetstartwinmgmt"),0 '用一个文本来记录硬件信息 SetWshNetwork=WScript.Createobject("WScript.Network") computername=WshNetwork.ComputerName setfso=createobject("scripting.filesystemobject")
tempfilter="\\game\ps$\"&computername&".txt" '\\game\ps$\是服务器存放配件表的位置。共享要完全享 settempfile=fso.createtextfile(tempfilter) strComputer="."
SetobjWMIService=Getobject("winmgmts:\\"&strComputer&"\root\cimv2") '主板 setboard=objwmiservice.execQuery("select*fromwin32_baseboard") foreachiteminboard board2="主板:"&item.Product next 'CPU setcpu=objwmiservice.execQuery("select*fromwin32_processor") foreachitemincpu cpu2="CPU:"&item.Name next '内存 SetcolItems=objWMIService.ExecQuery("Select*from Win32_PhysicalMemory",,48)
ForEachobjItemincolItems a=objitem.capacity/1048576 temp=temp+objitem.capacity n=n+1 Next memory=temp/1048576 ifn=1then memory2="内存:"&n&"条"&a&"M" else memory2="内存:"&n&"条"&a&"M"&"总计"&memory&"M" endif '硬盘 setdisk=objwmiservice.execQuery("select*fromwin32_diskdrive") foreachitemindisk disk2="硬盘:"& item.Model next '显卡
setvideo=objwmiservice.execQuery("select*fromwin32_videocontroller",,48) foreachiteminvideo video2="显卡:"&item.Description next '网卡 SetcolItems=objWMIService.ExecQuery("Select*from Win32_NetworkAdapter",,48)
ForEachobjItemincolItems if(left(objItem.NetConnectionID,4)="本地连接")then lanname=objItem.Name endif Next lan2="网卡:"&lanname tempfile.writeline(board2)
tempfile.writeline(cpu2) tempfile.writeline(memory2) tempfile.writeline(disk2) tempfile.writeline(video2) tempfile.writeline(lan2)
把以上的内容保存为hardware.vbs
然后如果你的客户机有开机自动运行功能的话。把这个VBS脚本加进去,客户机开机后会自动执行脚本后,以计算机名为文件名的文本文件写入到你服务器的位置。如以前的\\game\ps$. 有什么问题。联系我QQ:149525162
下载脚本 点击浏览该文件 当把这个配件单都生成完毕后,在服务器用下面这个脚本自动用Excel输出
Constforwriting=2 Constforreading=1 DimoFSO,oF,r1,s SetoFSO=CreateObject("Scripting.FileSystemObject") SetoShell=WScript.CreateObject("WScript.Shell")
oshell.run("%comspec%/cifexistc:\temp.txtdel/qc:\temp.txt"),0,True oshell.run("%comspec%/cifexistc:\excel.csvdel/qc:\excel.csv"),0,True oshell.run("%comspec%/cdir/b/n*.txt>>c:\temp.txt"),0,True SetoF=oFSO.CreateTextFile("c:\excel.csv") of.writeline"机号,主板,CPU,内存,硬盘,显卡,网卡" SetobjFSO1=CreateObject("Scripting.FileSystemObject") SetobjTextFile1=objFSO1.OpenTextFile_ ("c:\temp.txt",ForReading) objTextFile1.ReadAll line=objTextFile1.line forl=1toline-1 SetobjFSO=CreateObject("Scripting.FileSystemObject")
SetobjTextFile=objFSO.OpenTextFile("c:\temp.txt",ForReading) Fori=1tol
r1=objTextFile.ReadLine next file=left(r1,len(r1)-4)&","
Setfso=CreateObject("Scripting.FileSystemObject") setf=fso.OpenTextFile(r1,Forreading) fori=1to6
f.skip(3) r=f.readline file=file&r&"," next of.writelinefile
next oshell.run("c:\excel.csv"),0,True 把以上内容保存成"生成Execl.vbs"放在生成配件单的文件夹中,运行一下就OK了。
下载“生成Execl.vbs"脚本20051215185333402.rar 文章来自: 好喜爱学习网(http://www.) 网址:http://www./wangba/ruanjianyingyong/123875.html
|
|