用VBScript收集系统信息并上传到ftp空间
来源: 阅读:1456 次 日期:2016-07-07 15:30:33
温馨提示: 小编为您整理了“用VBScript收集系统信息并上传到ftp空间”,方便广大网友查阅!

这个脚本的功能是运行后自动将查询到的计算机相关信息记录到一个文档中,然后在经过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)

'#####自删除_结束#####

更多信息请查看脚本栏目
由于各方面情况的不断调整与变化, 提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!

2025国考·省考课程试听报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
关于我们 | 联系我们 | 人才招聘 | 网站声明 | 网站帮助 | 非正式的简要咨询 | 简要咨询须知 | 加入群交流 | 手机站点 | 投诉建议
工业和信息化部备案号:滇ICP备2023014141号-1 云南省教育厅备案号:云教ICP备0901021 滇公网安备53010202001879号 人力资源服务许可证:(云)人服证字(2023)第0102001523号
云南网警备案专用图标
联系电话:0871-65317125(9:00—18:00) 获取招聘考试信息及咨询关注公众号:
咨询QQ:526150442(9:00—18:00)版权所有:
云南网警报警专用图标
Baidu
map