VBS 获取指定电脑的部分信息...

该VBScript脚本能够批量获取远程计算机的部分信息,并自动填充到Excel表格中。信息包括域名、IP地址、制造商、型号及序列号等。脚本通过WMI查询Win32_SystemEnclosure类来获取所需数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Program Name: Get_Remote_PC_Partial_Information.vbs

----The Code as Below

'--------------------------

'Author By: Wei_Zhu

'Creation Date: 2010-03-08

'--------------------------

On Error Resume Next

Const ForReading = 1, ForWriting = 2, ForAppending = 8

Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

Set objExcel = CreateObject("Excel.Application")

Set objWorkbook=objExcel.Workbooks.Add() 'This is add new

Set objRange = objExcel.Range("A1","E1")

objRange.Font.Size = 10

objrange.Font.Bold = True

objrange.Font.Name = "Times New Roman"

objrange.Cells(1).Value="Domain"

objrange.Cells(2).Value="IP"

objrange.Cells(3).Value="Manufacturer"

objrange.Cells(4).Value="Model"

objrange.Cells(5).Value="Serial Number"

objrange.Interior.ColorIndex = 34 'Set BackColor

objRange.Borders.LineStyle = 1

Set objRange = objExcel.ActiveCell.EntireColumn

objRange.AutoFit()

'----Auto Fill The Column Width---

Set objcol = objExcel.Columns("A:E").EntireColumn

objcol.AutoFit

set ws=createobject("wscript.shell")

set fso=createobject("scripting.filesystemobject")

set folder=fso.getfolder(ws.CurrentDirectory&"\Computer")

Set fc = folder.Files

For Each f1 in fc

s = folder&"\" & f1.name

set ts = fso.OpenTextFile(s, ForReading)

lint_line =2

Do While Not ts.AtEndOfStream

l_ip = ts.ReadLine

GetPCInfo l_ip,f1.Name,lint_line

lint_line = lint_line +1

Loop

lint_line=0

ts.Close

Next

objExcel.DisplayAlerts = False 'Close the Alert

'objExcel.ActiveWorkBook.Saveas lstg_to_f,-4143

'msgbox lstg_to_f

objExcel.ActiveWorkBook.Saveas folder&".xls",-4143

objExcel.DisplayAlerts = False ''Close the Save Alert

objExcel.ActiveWorkbook.Close

objExcel.DisplayAlerts = False

objExcel.Application.Quit

Function GetPCInfo(ByVal ip, ByVal l_fn, ByVal l_line)

'Function GetPCInfo(l_fn,l_line)

strComputer = ip

objWMIService = GetObject("winmgmts:" _

& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

colItems = objWMIService.ExecQuery("Select * from Win32_SystemEnclosure")

l_Array = Split(l_fn, ".", -1, 1)

For Each objItem In colItems

'MsgBox "Manufacturer: " & objItem.Manufacturer

' Msgbox "Product: " & objItem.Product

' Msgbox "Serial Number: " & objItem.SerialNumber

objRange = objExcel.Range("A" & l_line, "E" & l_line)

objRange.Cells(1).value = l_Array(0)

objRange.Cells(2).value = ip

objRange.Cells(3).value = objItem.Manufacturer

objRange.Cells(4).value = objItem.Model

objRange.Cells(5).value = objItem.SerialNumber

Next

'----Auto Fill The Column Width---

objcol = objExcel.Columns("A:E").EntireColumn

objcol.AutoFit()

'----Note----
The Win Server 2003 or high must class Win32_SystemEnclosure get Manufacturer information,...etc.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值