' inventory.vbs ' Script para inventário de hardware e software ' Autor Tiago Leal - tiagoleal.ssa@gmail.com ' Versão Beta 2 - 09/08/2011 ' O Script está em fase experimental. Aceito sugestões e melhorias. ' O script foi testado apenas no windows xp 32bits. On Error Resume Next ' LOCAL ONDE SERÁ SALVO O RELATÓRIO (atentar para a barra no final) Dim DIRPATH DIRPATH = Wscript.Arguments.Item(0) If IsEmpty(DIRPATH) Then DIRPATH = ".\" End If Set WshNetwork = WScript.CreateObject("WScript.Network") FilePath = LCase(DIRPATH & WshNetwork.ComputerName & ".html") Err.Clear Set fso = CreateObject("scripting.filesystemobject") Set oFile = fso.OpenTextFile(FilePath,2,True) If Err.Number <> 0 Then Wscript.Echo "Erro criando arquivo " & FilePath & ": " & Err.Description & ". Abortando..." WScript.Quit End If ' Constantes WMI Const NET = "Win32_NetworkAdapterConfiguration" Const OS = "Win32_OperatingSystem" Const PROC = "Win32_Processor" Const MEM = "Win32_PhysicalMemory" Const DISK = "Win32_DiskDrive" Const PART = "Win32_LogicalDisk" Const PRINT = "Win32_Printer" Const DEV = "Win32_PnPEntity" Const SO = "Win32_OperatingSystem" Const HKLM = &H80000002 ' Classes de dispositivos http://msdn.microsoft.com/en-us/library/ff553426%28v=vs.85%29.aspx Const CNIC = "{4d36e972-e325-11ce-bfc1-08002be10318}" 'adaptadores de rede Const CVGA = "{4d36e968-e325-11ce-bfc1-08002be10318}" 'adaptadores de vídeo Const CMMD = "{4d36e96c-e325-11ce-bfc1-08002be10318}" 'som, vídeo e jogo Const CIDE = "{4d36e96a-e325-11ce-bfc1-08002be10318}" 'controladora IDE Const CSCSI = "{4d36e97b-e325-11ce-bfc1-08002be10318}" 'controladora SCSI Const CUSB = "{36fc9e60-c465-11cf-8056-444553540000}" 'controladora USB Const CMON = "{4d36e96e-e325-11ce-bfc1-08002be10318}" 'monitor Const CMOUSE = "{4d36e96f-e325-11ce-bfc1-08002be10318}" 'mouse Const CPORT = "{4d36e978-e325-11ce-bfc1-08002be10318}" 'portas COM e LPT Const CPROC = "{50127dc3-0f36-415e-a6cc-4cb3be910b65}" 'processador Const CKEY = "{4d36e96b-e325-11ce-bfc1-08002be10318}" 'teclado Const CDISK = "{4d36e967-e325-11ce-bfc1-08002be10318}" 'disco Const CDVD = "{4d36e965-e325-11ce-bfc1-08002be10318}" 'cdrom e dvd Const CVOL = "{71a27cdd-812a-11d0-bec7-08002be2092f}" 'volumes ' Objeto WMI Set WMI = GetObject("winmgmts:{impersonationlevel=impersonate}!") ' INÍCIO DA PÁGINA oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("Inventário da máquina " & WshNetwork.ComputerName & "") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("

Inventário da máquina " & WshNetwork.ComputerName & "

") oFile.WriteLine("

Gerado em " & Date & " às " & Time & "

") oFile.WriteLine("
") ' INFORMAÇÕES GERAIS Set objSO = WMI.ExecQuery("SELECT * FROM " & SO) oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") WScript.DisconnectObject(WshNetwork) For Each oSO In objSO If Not IsNull(oSO) Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") End If Next oFile.WriteLine("
Informações Gerais
Hostname" & WshNetwork.ComputerName & "
Usuário" & WshNetwork.UserName & "
Domínio" & WshNetwork.UserDomain & "
SO" & oSO.Caption & " Service Pack " & oSO.ServicePackMajorVersion & "
Versão do SO" & oSO.Version & "
") WScript.DisconnectObject(objSO) ' CONFIGURAÇÕES DE REDE Set objNet = WMI.ExecQuery("SELECT * FROM " & NET & " WHERE IPEnabled = True") oFile.WriteLine("
") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oNet In objNet If Not IsNull(oNet) Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") If IsArray(oNet.DefaultIPGateway) Then oFile.WriteLine("") Else oFile.WriteLine("") End If If IsArray(oNet.DNSServerSearchOrder) Then oFile.WriteLine("") Else oFile.WriteLine("") End If oFile.WriteLine("") oFile.WriteLine("") End If Next oFile.WriteLine("
Configurações de Rede
IPMáscara de SubredeGatewayDNSMAC
" & oNet.IPAddress(0) & "" & oNet.IPSubnet(0) & "" & oNet.DefaultIPGateway(0) & "N/A") For i=0 To UBound(oNet.DNSServerSearchOrder) Step 1 oFile.WriteLine(oNet.DNSServerSearchOrder(i) & "
") Next oFile.WriteLine("
N/A" & oNet.MACAddress & "
") WScript.DisconnectObject(objNet) ' MEMÓRIA Set objMem = WMI.ExecQuery("SELECT DeviceLocator,Capacity FROM " & MEM) oFile.WriteLine("
") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Dim totalMemory For Each oMem In objMem If Not IsNull(oMem) Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") totalMemory = totalMemory + oMem.Capacity/1024/1024 End If Next oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("
Memória
LocalQuantidade (MB)
" & oMem.DeviceLocator & "" & oMem.Capacity/1024/1024 & "
Total: " & totalMemory &"
") WScript.DisconnectObject(objMem) ' PROCESSADOR Set objProc = WMI.ExecQuery("SELECT Name,MaxClockSpeed,NumberOfCores,L2CacheSize FROM " & PROC) oFile.WriteLine("
") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!//./root/default:StdRegProv") objReg.GetStringValue HKLM,"HARDWARE\DESCRIPTION\System\CentralProcessor\0","ProcessorNameString",strProcName For Each oProc In objProc If Not IsNull(oProc) Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") End If Next oFile.WriteLine("
Processador
NomeClock (Mhz)NúcleoCache L2 (KB)
" & strProcName & "" & oProc.MaxClockSpeed & "" & oProc.NumberOfCores & "" & oProc.L2CacheSize & "
") WScript.DisconnectObject(objProc) ' DISCO e PARTIÇÕES Set objDisk = WMI.ExecQuery("SELECT * FROM " & DISK & " Where InterfaceType <> 'USB'") oFile.WriteLine("
") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDisk In objDisk If Not IsNull(oDisk) Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") End If Next WScript.DisconnectObject(objDisk) Set objPart = WMI.ExecQuery("SELECT * FROM " & PART & " WHERE DriveType=3") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oPart In objPart If Not IsNull(oPart) Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") End If Next oFile.WriteLine("
Disco
ModeloCapacidade (GB)Partições
" & oDisk.Model & "" & Round(oDisk.Size/(1024^3)) & "" & oDisk.Partitions & "
Partições
UnidadeTamanho (GB)Espaço Livre (GB)Tipo
" & oPart.Name & "" & Round(oPart.Size/(1024^3)) & "" & Round(oPart.FreeSpace/(1024^3)) & "" & oPart.FileSystem & "
") WScript.DisconnectObject(objPart) ' DISPOSITIVOS oFile.WriteLine("
") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") ' Placas de Rede Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CNIC & "' And Manufacturer <> 'Microsoft'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each nic In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) ' Placas de Vídeo Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CVGA & "' And Manufacturer <> 'Microsoft'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDev In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) ' Multimídia (som, vídeo e jogo) Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CMMD & "' And Manufacturer <> 'Microsoft'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDev In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) ' Controladora IDE/ATAPI Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CIDE & "' And Manufacturer <> 'Microsoft'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDev In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) ' Conroladora SCSI/RAID Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CSCSI & "' And Manufacturer <> 'Microsoft'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDev In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) ' Controladora USB Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CUSB & "' And Manufacturer <> 'Microsoft'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDev In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) ' Monitor Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CMON & "' And Manufacturer <> 'Microsoft'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDev In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) ' Mouse e teclado Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CMOUSE & "' Or ClassGuid = '" & CKEY & "'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDev In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) ' Portas serial e paralela Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CPORT & "' And Manufacturer <> 'Microsoft'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDev In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) ' Processador Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CPROC & "'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDev In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) ' Disco Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CDISK & "' And Manufacturer <> 'Microsoft'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDev In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) ' Cdrom e DVDrom Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CDVD & "' And Manufacturer <> 'Microsoft'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDev In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) ' Volumes Set objDev = WMI.ExecQuery("SELECT ClassGuid,Caption,Description,Manufacturer,Name FROM " & DEV & " WHERE ClassGuid = '" & CVOL & "'") If Not IsNull(objDev) And objDev.Count > 0 Then oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") For Each oDev In objDev oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") Next End If WScript.DisconnectObject(objDev) oFile.WriteLine("
Dispositos
TipoNomeFabricanteDescrição
Rede
" & nic.Name & "" & nic.Manufacturer & "" & nic.Description & "
Vídeo
" & oDev.Name & "" & oDev.Manufacturer & "" & oDev.Description & "
Som, vídeo e jogo
" & oDev.Name & "" & oDev.Manufacturer & "" & oDev.Description & "
Controladora IDE
" & oDev.Name & "" & oDev.Manufacturer & "" & oDev.Description & "
Controladora SCSI/RAID
" & oDev.Name & "" & oDev.Manufacturer & "" & oDev.Description & "
Controladora USB
" & oDev.Name & "" & oDev.Manufacturer & "" & oDev.Description & "
Monitor
" & oDev.Name & "" & oDev.Manufacturer & "" & oDev.Description & "
Mouse e teclado
" & oDev.Name & "" & oDev.Manufacturer & "" & oDev.Description & "
Portas COM e LPT
" & oDev.Name & "" & oDev.Manufacturer & "" & oDev.Description & "
Processador
" & oDev.Name & "" & oDev.Manufacturer & "" & oDev.Description & "
Disco
" & oDev.Name & "" & oDev.Manufacturer & "" & oDev.Description & "
DVD/CDROM
" & oDev.Name & "" & oDev.Manufacturer & "" & oDev.Description & "
Volumes
" & oDev.Name & "" & oDev.Manufacturer & "" & oDev.Description & "
") ' PROGRAMAS oFile.WriteLine("
") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") oFile.WriteLine("") strComputer = "." strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" strDisplayName = "DisplayName" strQDisplayName = "QuietDisplayName" strVersionMajor = "VersionMajor" strVersionMinor = "VersionMinor" strEstimatedSize = "EstimatedSize" strPublisher = "Publisher" Set objReg = GetObject("winmgmts:{impersonationLevel=impersonate}!//" & strComputer & "/root/default:StdRegProv") objReg.EnumKey HKLM,strKey,arrSubKeys For i=0 To UBound(arrSubKeys) Step 1 intRet1 = objReg.GetStringValue(HKLM, strKey & arrSubKeys(i), strDisplayName, strNome) If intRet1 = 0 Then ' Nome oFile.WriteLine("") If strNome <> "" Then oFile.WriteLine("") Else oFile.WriteLine("") End If ' Versão objReg.GetDWORDValue HKLM,strKey & arrSubKeys(i), strVersionMajor, intVersao objReg.GetDWORDValue HKLM,strKey & arrSubKeys(i), strVersionMinor, intVersaoMenor If intVersao <> "" Then oFile.WriteLine("") Else oFile.WriteLine("") End If ' Tamanho objReg.GetDWORDValue HKLM,strKey & arrSubKeys(i), strEstimatedSize, intTamanho If intTamanho <> "" Then oFile.WriteLine("") Else oFile.WriteLine("") End If ' Fabricante objReg.GetStringValue HKLM,strKey & arrSubKeys(i), strPublisher, strFabricante If strFabricante <> "" Then oFile.WriteLine("") Else oFile.WriteLine("") End If oFile.WriteLine("") End If Next WScript.DisconnectObject(objReg) oFile.WriteLine("
Programas Instalados
NomeVersãoTamanhoFabricante
" & strNome & "N/A" & intVersao & "." & intVersaoMenor & "N/A" & Round(intTamanho/1024,2) &"MBN/A" & strFabricante &"N/A
") oFile.WriteLine("
") oFile.WriteLine("") oFile.WriteLine("") WScript.DisconnectObject(WMI) oFile.Close() WScript.DisconnectObject(oFile) WScript.DisconnectObject(fso) Wscript.Echo "Inventário salvo em " & FilePath