Napisałem skrypt, który ma pobierać zdalnie informacje sprzętowe o komputerach. Listę komputerów pobiera z pliku Computers.txt a zapisuje do SysInfo.txt. Skrypt działa poprawnie tylko i wyłącznie dla lokalnego komputera, wpisując np. dwa adresy IP 192.168.100.2 oraz 192.168.100.3 niby je czyta, jednak informację zapisuje dwa razy dla komputera lokalnego lub nie zapisuje nic. Poniżej kod, będę wdzięczny za pomoc w rozwiązaniu problemu:
Kod: Zaznacz cały
on Error Resume Next Dim fso,objShell,writeFile,readFile,objWMIService,colSystem,colProcesor,colOperationSystem
Function FindOSType(strOSSys)
Dim objWMI, objItem, colItems
Dim OSVersion, OSName, ProductType
Set objWMI = GetObject("winmgmts://" & strOSSys & "/root/cimv2")
Set colItems = objWMI.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
OSVersion = Left(objItem.Version,3)
ProductType = objItem.ProductType
Next
Select Case OSVersion
Case "6.1"
OSName = "Windows 7/ 2008 R2"
Case "6.0"
OSName = "Windows Vista / 2008"
Case "5.2"
OSName = "Windows 2003"
Case "5.1"
OSName = "Windows XP"
Case "5.0"
OSName = "Windows 2000"
Case "4.0"
OSName = "Windows NT 4.0"
Case Else
OSName = "Windows 9x"
End Select
FindOSType = OSName
End Function
Const ForAppending = 8
Const ForReading = 1
Set objShell = WScript.CreateObject("WScript.Shell")
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
'Set objTextFile = objFSO.CreateTextFile("ProductKeys.txt" True)
Set writeFile = fso.OpenTextFile("SysInfo.txt",ForAppending)
Set readFile = fso.OpenTextFile("Computers.txt",ForReading)
Do While readFile.AtEndOfStream <> True
strComputer = readFile.ReadLine
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSystem = objWMIService.ExecQuery ("Select * from Win32_ComputerSystem")
Set colProcesor = objWMIService.ExecQuery ("Select * from Win32_Processor")
Set colHardDrive = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk")
Set colOperationSystem = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem ")
Set colCacheMemory = objWMIService.ExecQuery ("Select * from Win32_CacheMemory ")
For Each objComputer in colSystem
writeFile.WriteLine "Nazwa: " & objComputer.Name
writeFile.WriteLine " "
writeFile.WriteLine "Ram: " & Round(((objComputer.TotalPhysicalMemory)/1073537024),2) & " GB RAM"
writeFile.WriteLine " "
Next
For Each objProcesor in colProcesor
writeFile.WriteLine "Procesor: " & objProcesor.Name & objProcesor.MaxClockSpeed
writeFile.WriteLine "Rdzenie: " & objProcesor.NumberOfLogicalProcessors
writeFile.WriteLine "Cache L2: " & Round(((objProcesor.L2CacheSize)/1024),2) & " MB "
writeFile.WriteLine "Cache L3: " & Round(((objProcesor.L3CacheSize)/1024),2) & " MB "
writeFile.WriteLine " "
Next
For Each objOS in colOperationSystem
writeFile.WriteLine "OS: " & FindOsType(strComputer)
writeFile.WriteLine "Architektura: " & objOS.OSArchitecture
writeFile.WriteLine "SP: " & objOS.CSDVersion
writeFile.WriteLine " "
Next
For Each objHardDrive in colHardDrive
writeFile.WriteLine "Partycja " & objHardDrive.Name & " " & Round(((objHardDrive.Size)/1073537024),2) & " GB "
writeFile.WriteLine "Wolne miejsce: " & Round(((objHardDrive.FreeSpace)/1073537024),2) & " GB "
writeFile.WriteLine " "
Next
objShell.Popup strComputer, 1
writeFile.WriteLine "---------------------------------------------------------"
Loop
writeFile.Close
readFile.Close
Wscript.Echo "Skrypt zakończony..."