' **************************************************
' * Datei: Computerinfo.vbs. VB Skript Datei unter WSH 5.6
' * VBScript zum auslesen von Computerinformationen auf
' * lokalen oder Remotemaschinen mittels WQL Anfragen.
' *
' *
' * HINWEISE: Bentigt Excel ab Version 97
' *
' **************************************************
' **************************************************
 
' Excel-Tabelle ffnen und IP's sequentiell auslesen
 
Set oExcel = Wscript.CreateObject("Excel.Application")
' Excel-Tabelle laden
Set objWb = oExcel.WorkBooks.Open(GetPath & "ComputerInfo.xls")
' Arbeitsblatt holen
Set objWb = oExcel.ActiveWorkbook.Worksheets("Tabelle1")
' **********************************************************
' Anzahl der Eintrge der Excel-Tabelle ermitteln
Spalte = 1
sZeile = 1
Do
 sZeile = sZeile + 1
 text = CStr(objWb.Cells(sZeile, Spalte).Value)
Loop while text = ""
 
Zeile = sZeile
 
Do
 text = CStr(objWb.Cells(Zeile, Spalte).Value)
 Zeile = Zeile + 1
Loop until text = ""
 
LineCount = Zeile - sZeile - 1
' **********************************************************
 
 
For i = 0 to LineCount - 1
 AktuelleZeile = sZeile + i
 Spalte = 1
 ComputerIP = CStr(objWb.Cells(AktuelleZeile, Spalte).Value)
 GetAndWriteInfo AktuelleZeile, ComputerIP 
Next    
oExcel.save
oExcel.Quit
MsgBox "Computerinformationen wurden in die Tabelle eingetragen", vbInformation & vbOKOnly, "Fertig"
 
Sub GetAndWriteInfo(line, RemoteMachine)
'***************************************************
' Fehlerbehandlung aus. Treten Fehler auf, macht das Skript mit der nchsten Anweisung weiter 
' und ignoriert den Fehler
On Error Resume Next
' Die obige Anweisung bei Bedarf auskommentieren
' **************************************************
' alte Fehlercodes lschen
err.clear

 Set wmi = GetObject("winmgmts://" & RemoteMachine & "/root/cimv2")
 Set oComputer = wmi.ExecQuery("Select * from Win32_ComputerSystem")
If err.number <> 0 Then
 oExcel.Cells(line, 2).Value = "Fehler beim Abfragen der Informationen. Rechner mglicherweise nicht erreichbar."
 Set wmi = Nothing
    Set oComputer = Nothing
 Exit Sub
End If
 

  column = 1
 For each item in oComputer
  text = item.name ' Computername
   column = column + 1
   oExcel.Cells(line, column).Value = text
  text = item.domain ' Domnen- od. Arbeitsgruppenname
   column = column + 1
   oExcel.Cells(line, column).Value = text
  text = item.manufacturer ' Computerhersteller
   column = column + 1
   oExcel.Cells(line, column).Value = text
  text = item.model ' Computermodell
   column = column + 1
   oExcel.Cells(line, column).Value = text
 Next
  
 Set oProcessor = wmi.ExecQuery("Select * from Win32_Processor")
 For each item in oProcessor
  text = item.name & " " & item.caption ' Prozessor Typ
   column = column + 1
   oExcel.Cells(line, column).Value = text
  text = item.manufacturer ' Pozessorhersteller
   column = column + 1
   oExcel.Cells(line, column).Value = text
  text = item.currentclockspeed ' gegenwrtige Prozessorgeschwindigkeit
   column = column + 1
   oExcel.Cells(line, column).Value = text
 Next
 
 Set oRAM = wmi.ExecQuery("Select * from Win32_OperatingSystem") 
 For each item in oRAM
  text = item.TotalVisibleMemorySize ' Arbeitsspeichergre in KB
   column = column + 1
   oExcel.Cells(line, column).Value = text
 Next 
 
 Set oNIC = wmi.ExecQuery("Select * from Win32_NetworkAdapter where AdapterType = ""Ethernet 802.3""")
 For each item in oNIC
  text = item.name ' Modell bzw. Netzwerkkarten Name
   column = column + 1
   oExcel.Cells(line, column).Value = text
  text = item.MACAddress ' MAC Adresse
   column = column + 1
   oExcel.Cells(line, column).Value = text
 Next 
 
 Set oVideo = wmi.ExecQuery("Select * from Win32_VideoController")
 For each item in oVideo
  text = item.AdapterDACType ' Adapter Typ
   column = column + 1
   oExcel.Cells(line, column).Value = text
  text = item.caption ' Adapter Bezeichnung
   column = column + 1
   oExcel.Cells(line, column).Value = text
  text = item.adapterRAM ' Arbeitsspeicher der Grafikkarte
   column = column + 1
   oExcel.Cells(line, column).Value = text
 Next 
 
' Abfrage der Anzahl und Gre der Festplatte(n)
 Set oHDD = wmi.ExecQuery("Select * from Win32_DiskDrive")
 For each item in oHDD
 
  If item.deviceid = "\\.\PHYSICALDRIVE0" then
   text = item.caption ' Hersteller
    column = column + 1
    oExcel.Cells(line, column).Value = text
   text = item.interfacetype ' Abfrage IDE oder SCSI Interface
    column = column + 1
    oExcel.Cells(line, column).Value = text   
   text = item.size ' Festplattengre
    column = column + 1
    oExcel.Cells(line, column).Value = text
       
   anzahl = 1
  End If 
  
  If item.deviceid = "\\.\PHYSICALDRIVE1" then
   text = item.caption ' Hersteller
    column = column + 1
    oExcel.Cells(line, column).Value = text
   text = item.interfacetype ' Abfrage IDE oder SCSI Interface
    column = column + 1
    oExcel.Cells(line, column).Value = text   
   text = item.size ' Festplattengre
    column = column + 1
    oExcel.Cells(line, column).Value = text
       
   anzahl = 2
  End If
 
  If item.deviceid = "\\.\PHYSICALDRIVE2" then
   text = item.caption ' Hersteller
    column = column + 1
    oExcel.Cells(line, column).Value = text
   text = item.interfacetype ' Abfrage IDE oder SCSI Interface
    column = column + 1
    oExcel.Cells(line, column).Value = text   
   text = item.size ' Festplattengre
    column = column + 1
    oExcel.Cells(line, column).Value = text
       
   anzahl = 3
  End If
  
  If item.deviceid = "\\.\PHYSICALDRIVE3" then
   text = item.caption ' Hersteller
    column = column + 1
    oExcel.Cells(line, column).Value = text
   text = item.interfacetype ' Abfrage IDE oder SCSI Interface
    column = column + 1
    oExcel.Cells(line, column).Value = text   
   text = item.size ' Festplattengre
    column = column + 1
    oExcel.Cells(line, column).Value = text
       
   anzahl = 4
  End If
    
 Next
 
text = anzahl
column = 27
oExcel.Cells(line, column).Value = text
 
' Objekte freigeben
Set wmi = nothing
Set oComputer = Nothing
 
End Sub
 
 
Function GetPath
 path = WScript.ScriptFullName
 GetPath = Left(path, InStrRev(path, "\"))
End Function
