欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

用VBScript收集系统信息并上传到ftp空间

程序员文章站 2022-08-27 18:31:36
之前无聊整理出来了一份这个东西,因为在单位给新入职的员工配电脑时,需要登记一遍设备,可每次总要查感觉挺麻烦,结果下面的这份vbs脚本就诞生了,只可惜这个脚本做好了却没派上用...
之前无聊整理出来了一份这个东西,因为在单位给新入职的员工配电脑时,需要登记一遍设备,可每次总要查感觉挺麻烦,结果下面的这份vbs脚本就诞生了,只可惜这个脚本做好了却没派上用场哎。。。

这个脚本的功能是运行后自动将查询到的计算机相关信息记录到一个文档中,然后在经过ftp将生成的文件上传至服务器保存,最后在清除运行脚本是生成的文件并删除自身。

下面是代码:
复制代码 代码如下:

'#####收集计算机信息_开始#####
on error resume next
set fso = createobject("scripting.filesystemobject")
set f1 = fso.createtextfile("info")
strcomputer = "."
if err.description = "" then
'收集本地计算机名称
set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2")
set colitems = objwmiservice.execquery("select * from win32_computersystem", , 48)
j = 0
for each objitem in colitems
if j = 0 then f1.write (trim(objitem.name)) else f1.write (trim(objitem.name)) '收集本地计算机名称
j = j + 1
next
'收集计算机登录帐户
f1.write (chr(10))
f1.write (";")
f1.write (chr(10))
set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2")
set colitems = objwmiservice.execquery("select * from win32_computersystem", , 48)
j = 0
for each objitem in colitems
if j = 0 then f1.write (trim(objitem.username)) else f1.write (trim(objitem.username)) '收集计算机登录帐户
j = j + 1
next
'收集cpu信息
f1.write (chr(10))
f1.write (";")
f1.write (chr(10))
set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2")
set colitems = objwmiservice.execquery("select * from win32_processor", , 48)
j = 1
for each objitem in colitems
if j = 0 then f1.write (trim(objitem.name)) else f1.write (trim(objitem.name) & "||")
j = j + 1
next
'收集内存总容量
f1.write (chr(10))
f1.write (";")
f1.write (chr(10))
set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2")
set colitems = objwmiservice.execquery("select * from win32_computersystem", , 48)
j = 2
for each objitem in colitems
if j = 0 then f1.write (trim(objitem.totalphysicalmemory)/1024/1024 & " gb") else f1.write (trim(objitem.totalphysicalmemory)/1024/1024 & " gb" & "||")
j = j + 1
next
'收集显卡信息
f1.write (chr(10))
f1.write (";")
f1.write (chr(10))
set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2")
set colitems = objwmiservice.execquery("select * from win32_videocontroller", , 48)
j = 4
for each objitem in colitems
if j = 0 then f1.write (trim(objitem.caption) & (objitem.videomodedescription)) else f1.write (trim(objitem.caption) & (objitem.videomodedescription) & "||")
j = j + 1
next
'收集硬盘基本信息
f1.write (chr(10))
f1.write (";")
f1.write (chr(10))
set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2")
set colitems = objwmiservice.execquery("select * from win32_diskdrive", , 48)
j = 5
for each objitem in colitems
if j = 0 then f1.write (trim(objitem.model) & (objitem.size)/1024/1024/1024 & " gb" & (objitem.partitions)) else f1.write (trim(objitem.model) & "--" & (objitem.size)/1024/1024/1024 & " gb" & "--" & (objitem.partitions) & "||")
j = j + 1
next
'收集声卡信息
f1.write (chr(10))
f1.write (";")
f1.write (chr(10))
set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2")
set colitems = objwmiservice.execquery("select * from win32_sounddevice", , 48)
j = 6
for each objitem in colitems
if j = 0 then f1.write (trim(objitem.productname)) else f1.write (trim(objitem.productname) & "||")
j = j + 1
next
'收集网卡信息
f1.write (chr(10))
f1.write (";")
f1.write (chr(10))
set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2")
set colitems = objwmiservice.execquery("select * from win32_networkadapter", , 48)
j = 7
for each objitem in colitems
if j = 0 then f1.write (trim(objitem.netconnectionid) & (objitem.description) & (objitem.macaddress) & (objitem.manufacturer)) else f1.write (trim(objitem.netconnectionid) & "--" & (objitem.productname) & "--" & (objitem.macaddress) & "--" &(objitem.manufacturer) & "||")
j = j + 1
next
end if
f1.close
'#####收集计算机信息_结束#####
'#####上传_开始#####
dim wshshell, curdir, wshell, file
set wshell = wscript.createobject("shell.application")
set wshshell = wscript.createobject("wscript.shell")
set filesystem = wscript.createobject("scripting.filesystemobject")
set outputfile = filesystem.opentextfile("upload",2,true)
set objwmiservice = getobject("winmgmts:\\" & strcomputer & "\root\cimv2")
set colitems = objwmiservice.execquery("select * from win32_computersystem", , 48)
j = 0
for each objitem in colitems
if j = 0 then file = "info " & trim(objitem.name) & ".csv" else file = "info " & trim(objitem.name) & ".csv"
j = j + 1
next
outputfile.writeline "open 192.168.0.254 2020"
outputfile.writeline "user iplog iplog"
outputfile.writeline "put " & file
outputfile.writeline "bye"
outputfile.close
wshshell.run "ftp -n -s:upload"

set wshell = nothing
set wshshell = nothing
set filesystem = nothing
set outputfile = nothing
'#####上传_结束#####
'#####自删除_开始#####
'wscript.sleep 2000
'set obj = createobject("scripting.filesystemobject")
'obj.deletefile("upload")
'obj.deletefile("info")
'obj.deletefile(wscript.scriptname)
wscript.quit(0)
'#####自删除_结束#####

上传到ftp地址
open 192.168.0.254 2020
user iplog iplog
put info mdxy.csv
bye