itfreak
Goto Top

VBS Inventar Script funktioniert nicht

Moin Moin

Wollte dieses Skript einsetzten aus irgendwelchen Gründen die mir nicht bekannt sind, funktioniert das ganze nicht,
bekomme keine Fehlermeldung nix. Weiss jemand woran das liegen könnte?

Vielen Dank für die Hilfe im voraus.

Gruss Itfreak

Const HKEY_LOCAL_MACHINE = &H80000002 
Const FOR_WRITING = 2 
Const ForReading = 1 
 
Set objFso = CreateObject("Scripting.FileSystemObject")   
Set objShell = CreateObject("WScript.Shell")   
 
Set oList = objFso.OpenTextFile("clients.txt",ForReading)   
Do While Not oList.AtEndOfStream 
    strComputername = oList.ReadLine 
    If Left(strComputername,1) <> ";" Then   
        If HostOnline(strComputername) = True Then 
            Inventory(strComputername) 
        End If 
    End If 
Loop 

'==========================================================================   
 
Function Inventory(strComputername) 
    On Error Resume Next 
     
    objOS.OSArchitecture = ""  
    Set oTextFile = objFso.OpenTextFile(strComputername & ".txt", FOR_WRITING, TRUE)   
     
    'oTextFile.WriteLine strComputername   
     
    Set objWMIService = GetObject("winmgmts:" _   
     & "{impersonationLevel=impersonate}!\\" & strComputername & "\root\cimv2")   
  
    Set colOSes = objWMIService.ExecQuery("Select * from Win32_OperatingSystem")   
    For Each objOS in colOSes 
          oTextFile.WriteLine "Computer Name: " & objOS.CSName   
          oTextFile.WriteLine "Caption: " & objOS.Caption   
          oTextFile.WriteLine "Version: " & objOS.Version   
          oTextFile.WriteLine "Build Number: " & objOS.BuildNumber   
          oTextFile.WriteLine "Build Type: " & objOS.BuildType   
          oTextFile.WriteLine "OS Type: " & objOS.OSType   
	  oTextFile.WriteLine "OS Architecture: " & objOS.OSArchitecture  
          oTextFile.WriteLine "Other Type Description: " & objOS.OtherTypeDescription   
          oTextFile.WriteLine "Service Pack: " & objOS.ServicePackMajorVersion & "." & objOS.ServicePackMinorVersion   
    Next 
     
    Set colProcs = objWMIService.ExecQuery("Select * from Win32_ComputerSystem")   
 
    For Each objItem in colProcs 
        oTextFile.WriteLine "Number of Processors: " & objItem.NumberOfProcessors   
    Next 
     
    oTextFile.WriteLine vbCrLf & "Applications:"   
 
    Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputername & "\root\default:StdRegProv")   
     
    strKeyPath = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"   
    objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys 
 
    For Each subkey In arrSubKeys 
        strSubKeyPath = strKeyPath & "\" & subkey   
         
        strString = "DisplayName"   
        objReg.GetStringValue HKEY_LOCAL_MACHINE, strSubKeyPath, strString, strDisplayName 
         
        strString = "DisplayVersion"   
        objReg.GetStringValue HKEY_LOCAL_MACHINE, strSubKeyPath, strString, strDisplayVersion 
         
        strString = "Publisher"   
        objReg.GetStringValue HKEY_LOCAL_MACHINE, strSubKeyPath, strString, strDisplayPublisher 

        strDisplayName=Trim(strDisplayName) 
        strDisplayVersion=Trim(strDisplayVersion) 
        strDisplayPublisher=Trim(strDisplayPublisher)
 	If strDisplayName <> "" Then   
            oTextFile.WriteLine strDisplayPublisher & ";" & strDisplayName & ";" & strDisplayVersion		  
        End If 

      Next


      strKeyPath = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"   
      objReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys 
 
      For Each subkey In arrSubKeys 
          strSubKeyPath = strKeyPath & "\" & subkey   
           
          strString = "DisplayName"   
          objReg.GetStringValue HKEY_LOCAL_MACHINE, strSubKeyPath, strString, strDisplayName 
         
          strString = "DisplayVersion"   
          objReg.GetStringValue HKEY_LOCAL_MACHINE, strSubKeyPath, strString, strDisplayVersion 
         
          strString = "Publisher"   
          objReg.GetStringValue HKEY_LOCAL_MACHINE, strSubKeyPath, strString, strDisplayPublisher 

          strDisplayName=Trim(strDisplayName) 
          strDisplayVersion=Trim(strDisplayVersion) 
         If strDisplayName = "" Then  
			oTextFile.WriteLine strDisplayPublisher & ";" & strDisplayName & ";" & strDisplayVersion  
            
          End If 
      Next 

    oTextFile.WriteLine "EOF"   
 
    objTextFile.close 

End Function 

'==========================================================================   
 
Function Output(sOutput) 
    WScript.echo Date() & " " & Time() & vbTab & sOutput   
End Function 

'==========================================================================   
 
Function HostOnline(strComputername) 
    Set sTempFolder = objFso.GetSpecialFolder(TEMPFOLDER) 
    sTempFile = objFso.GetTempName 
    sTempFile = sTempFolder & "\" & sTempFile   

 
    objShell.Run "cmd /c ping -n 2 -l 8 " & strComputername & ">" & sTempFile,0,True   
     
    Set oFile = objFso.GetFile(sTempFile) 
    set oTS = oFile.OpenAsTextStream(ForReading) 
    do while oTS.AtEndOfStream <> True 
        sReturn = oTS.ReadLine 
        if instr(sReturn, "Antwort")>0 then   
            HostOnline = True 
            Exit Do 
        End If 
    Loop 
     
    ots.Close 
    oFile.delete 
End Function 
 
'==========================================================================   
 
oList.Close 
Set objReg = Nothing 
Set objFso = Nothing 

Content-Key: 183146

Url: https://administrator.de/contentid/183146

Printed on: April 23, 2024 at 13:04 o'clock

Member: mak-xxl
mak-xxl Apr 05, 2012 at 09:44:30 (UTC)
Goto Top
Moin Itfreak,

wenn die Datei <clients.txt> (siehe Zeile 8) einen Eintrag eines Client-PCs, etwa so: "192.168.1.1" (ohne Literale) enthält, wird im gleichen Verzeichnis nach Scriptlauf eine Datei <192.168.1.1.txt> (siehe Zeile 24) liegen, in der das Script gefundene Infos zum Client-PC abgelegt hat.

Freundliche Grüße von der Insel - Mario
Member: netzwerkknecht
netzwerkknecht Apr 06, 2012 at 03:57:57 (UTC)
Goto Top
Die etwas ungelenke Ping-Abfrage in HostOnline setzt voraus, dass auf dem ausführenden Computer ein deutschsprachiges Windows eingesetzt wird: Auf einem englischsprachigen System wird ein Ping keinen String "Antwort" generieren, demnach gälten sämtliche abgefragten Rechner aus clients.txt als offline = keine Aktion. Für diesen Fall weist das Original des Codes unter http://gallery.technet.microsoft.com/scriptcenter/c1cbd0ea-2eda-48f8-8d ... aus, dass ein "Reply" erwartet würde.

netzwerkknecht auf Windows Intune: http://bit.ly/wide12hp