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

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.

posted on 2010-03-18 09:06  封起De日子  阅读(186)  评论(0编辑  收藏  举报

导航