Inventario - Base - Copia - Vbs

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 9

Const ForWriting = 2

On Error Resume Next

Set objNTInfo = WScript.CreateObject("WinNTSystemInfo")


strFileName = objNTInfo.ComputerName
WScript.Echo "Iniciando Inventario de: " & strFileName

If Err.number <> 0 Then

Set objNTInfo = WScript.CreateObject( "WScript.Shell" )


strFileName = objNTInfo.ExpandEnvironmentStrings( "%COMPUTERNAME%" )
WScript.Echo "Iniciando Inventario de" & strFileName

Err.Clear

End If

Dim d : d = Date()
Dim dateStr : dateStr = Year(d) & "-" & Right("00" & Month(d), 2) & "-" &
Right("00" & Day(d), 2)

On Error Resume Next

strComputer = "."
strUserName = "Administrador"
strPassword = "*Rollo48*" 'Poner la contrase�a entre las comillas
strPath = "\\192.168.0.14\Test"

Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")


Set objNet = WScript.CreateObject("WScript.Network")

objNet.MapNetworkDrive "", strPath, false, strUserName, strPassword


If Err.Number <> 0 Then

fullpath = objFSO.GetAbsolutePathName(folderName)
WScript.Echo "El inventario se guardar� de forma local en: " & fullpath

Else

fullpath = strPath
WScript.Echo "El inventario se guardar� en el recurso: " & fullpath

Err.Clear

End If

'-----------------------------------------------------EQUIPO
--------------------------------------

strFullName = fullpath & "\" & "01_HW_" & strFileName & "_" & dateStr
Set objLogFile = objFSO.CreateTextFile(strFullName & ".csv", ForWriting, True)

objLogFile.Writeline
objLogFile.Write "EQUIPO VIA WMI"
objLogFile.Writeline

objLogFile.Write "Caption" & vbtab


objLogFile.Write "Domain" & vbtab
objLogFile.Write "Manufacturer" & vbtab
objLogFile.Write "Model" & vbtab
objLogFile.Write "NumberOfLogicalProcessors" & vbtab
objLogFile.Write "NumberOfProcessors" & vbtab
objLogFile.Write "System Type" & vbtab

objLogFile.Writeline

On Error Resume Next

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")


Set colItems = objWMIService.ExecQuery( _
"SELECT * FROM Win32_ComputerSystem",,48)

For Each objItem in colItems

objLogFile.Write objItem.Caption & vbtab


objLogFile.Write objItem.Domain & vbtab
objLogFile.Write objItem.Manufacturer & vbtab
objLogFile.Write objItem.Model & vbtab
objLogFile.Write objItem.NumberOfLogicalProcessors & vbtab
objLogFile.Write objItem.NumberOfProcessors & vbtab
objLogFile.Write objItem.SystemType & vbtab
objLogFile.Writeline
Next

If Err.Number <> 0 Then


objLogFile.Writeline
objLogFile.Write "Error Equipo WMI: " & Err.Number & vbtab
objLogFile.Write "Error (Hex): " & Hex(Err.Number) & vbtab
objLogFile.Write "Source: " & Err.Source & vbtab
objLogFile.Write "Description: " & Err.Description
objLogFile.Writeline
Err.Clear
End If

objLogFile.Writeline
objLogFile.Write "EQUIPO VIA REGISTRO"
objLogFile.Writeline

objLogFile.Write "Nombre del Equipo" & vbtab


objLogFile.Write "Fabricante del Equipo" & vbtab
objLogFile.Write "Modelo" & vbtab
objLogFile.Write "Num de Procesadores" &vbtab
objLogFile.Write "Virtual Machine Name" &vbtab
objLogFile.Write "Physical Host Name" &vbtab

objLogFile.Writeline

On Error Resume Next

Const HKLM = &H80000002


Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")

strRegKey = "SYSTEM\CurrentControlSet\Control\"
strRegSub1 = "SystemInformation"
strRegSub2 = "ComputerName\ComputerName"
strRegSub3 = "Session Manager\Environment"
strRegKey1 = "SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters"

objReg.GetStringValue HKLM, strRegKey & strRegSub2, "ComputerName", strValue


objLogFile.Write strValue & vbtab

objReg.GetStringValue HKLM, strRegKey & strRegSub1, "SystemManufacturer",


strValue
objLogFile.Write strValue & vbtab

objReg.GetStringValue HKLM, strRegKey & strRegSub1, "SystemProductName",


strValue
objLogFile.Write strValue & vbtab

objReg.GetStringValue HKLM, strRegKey & strRegSub3, "NUMBER_OF_PROCESSORS",


strValue
objLogFile.Write strValue & vbtab

objReg.GetStringValue HKLM, strRegKey1 , "VirtualMachineName", strValue


objLogFile.Write strValue & vbtab

objReg.GetStringValue HKLM, strRegKey1 , "PhysicalHostName", strValue


objLogFile.Write strValue & vbtab

objLogFile.Writeline

If Err.Number <> 0 Then


objLogFile.Writeline
objLogFile.Write "Error Equipo Registro: " & Err.Number & vbtab
objLogFile.Write "Error (Hex): " & Hex(Err.Number) & vbtab
objLogFile.Write "Source: " & Err.Source & vbtab
objLogFile.Write "Description: " & Err.Description
objLogFile.Writeline
Err.Clear
End If

objLogFile.Writeline
objLogFile.Write "FIN DE REPORTE"
objLogFile.Writeline

objLogFile.Close
'-----------------------------------------------------SISTEMA
OPERATIVO----------------------------

strFullName = fullpath & "\" & "02_SO_" & strFileName & "_" & dateStr
Set objLogFile = objFSO.CreateTextFile(strFullName & ".csv", ForWriting, True)

objLogFile.Writeline
objLogFile.Write "SISTEMA OPERATIVO VIA WMI"
objLogFile.Writeline

objLogFile.Write "BuildType" & vbtab


objLogFile.Write "Caption" & vbtab
objLogFile.Write "CSDVersion" & vbtab
objLogFile.Write "Description" & vbtab
objLogFile.Write "NumberOfLicensedUsers" & vbtab
objLogFile.Write "SerialNumber" & vbtab
objLogFile.Write "OSArchitecture" & vbtab
objLogFile.Writeline

On Error Resume Next

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")


Set colItems1 = objWMIService.ExecQuery( _
"SELECT * FROM Win32_OperatingSystem",,48)

For Each objItem in colItems1


objLogFile.Write objItem.BuildType & vbtab
objLogFile.Write objItem.Caption & vbtab
objLogFile.Write objItem.CSDVersion & vbtab
objLogFile.Write objItem.Description & vbtab
objLogFile.Write objItem.NumberOfLicensedUsers & vbtab
objLogFile.Write objItem.SerialNumber & vbtab
objLogFile.Write objItem.OSArchitecture & vbtab

objLogFile.Writeline
Next

If Err.Number <> 0 Then


objLogFile.Writeline
objLogFile.Write "Error Sistema Operativo WMI: " & Err.Number & vbtab
objLogFile.Write "Error (Hex): " & Hex(Err.Number) & vbtab
objLogFile.Write "Source: " & Err.Source & vbtab
objLogFile.Write "Description: " & Err.Description
objLogFile.Writeline
Err.Clear
End If

objLogFile.Writeline
objLogFile.Write "SISTEMA OPERATIVO REGISTRO"
objLogFile.Writeline

objLogFile.Write "Sistema Operativo" & vbtab


objLogFile.Write "ServicePack" & vbtab
objLogFile.Write "Edicion" & vbtab
objLogFile.Write "Instalacion"

objLogFile.Writeline

On Error Resume Next


Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")

strRegKey = "SOFTWARE\Microsoft\Windows NT\CurrentVersion"

objReg.GetStringValue HKLM, strRegKey, "ProductName", strValue


objLogFile.Write strValue & vbtab

objReg.GetStringValue HKLM, strRegKey, "CSDVersion", strValue


objLogFile.Write strValue & vbtab

objReg.GetStringValue HKLM, strRegKey, "EditionID", strValue


objLogFile.Write strValue & vbtab

objReg.GetStringValue HKLM, strRegKey, "InstallationType", strValue


objLogFile.Write strValue
objLogFile.Writeline

If Err.Number <> 0 Then


objLogFile.Writeline
objLogFile.Write "Error Sistema Operativo Registro: " & Err.Number & vbtab
objLogFile.Write "Error (Hex): " & Hex(Err.Number) & vbtab
objLogFile.Write "Source: " & Err.Source & vbtab
objLogFile.Write "Description: " & Err.Description
objLogFile.Writeline
Err.Clear
End If

objLogFile.Writeline
objLogFile.Write "FIN DE REPORTE"
objLogFile.Writeline

objLogFile.Close

'-------------------------------------------LICENCIAMIENTO DE
WINDOWS--------------------------------

strFullName = fullpath & "\" & "03_Lic_" & strFileName & "_" & dateStr
Set objLogFile = objFSO.CreateTextFile(strFullName & ".csv", ForWriting, True)

objLogFile.Writeline
objLogFile.Write "LICENCIAIENTO"
objLogFile.Writeline

objLogFile.Write "Description" & vbtab


objLogFile.Write "LicenseFamily" & vbtab
objLogFile.Write "LicenseIsAddon" & vbtab
objLogFile.Write "LicenseStatus" & vbtab
objLogFile.Write "Name" & vbtab
objLogFile.Write "PartialProductKey" & vbtab

objLogFile.Writeline

On Error Resume Next

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")


Set colItems2 = objWMIService.ExecQuery( _
"SELECT * FROM SoftwareLicensingProduct",,48)

For Each objItem in colItems2


objLogFile.Write objItem.Description & vbtab
objLogFile.Write objItem.LicenseFamily & vbtab
objLogFile.Write objItem.LicenseIsAddon & vbtab
objLogFile.Write objItem.LicenseStatus & vbtab
objLogFile.Write objItem.Name & vbtab
objLogFile.Write objItem.PartialProductKey & vbtab
objLogFile.Writeline
Next

If Err.Number <> 0 Then


objLogFile.Writeline
objLogFile.Write "Error Licenciamiento WMI: " & Err.Number & vbtab
objLogFile.Write "Error (Hex): " & Hex(Err.Number) & vbtab
objLogFile.Write "Source: " & Err.Source & vbtab
objLogFile.Write "Description: " & Err.Description
objLogFile.Writeline
Err.Clear
End If

objLogFile.Writeline
objLogFile.Write "FIN DE REPORTE"
objLogFile.Writeline

objLogFile.Close
'--------------------------------------------CONFIGURACION DE
RED-----------------------------------

strFullName = fullpath & "\" & "04_Red_" & strFileName & "_" & dateStr
Set objLogFile = objFSO.CreateTextFile(strFullName & ".csv", ForWriting, True)

objLogFile.Writeline
objLogFile.Write "TARJETAS DE RED"
objLogFile.Writeline

objLogFile.Write "Caption" & vbtab


objLogFile.Write "Description" & vbtab
objLogFile.Write "DHCPServer" & vbtab
objLogFile.Write "DNSDomain" & vbtab
objLogFile.Write "DNSHostName" & vbtab
objLogFile.Write "IPXAddress" & vbtab
objLogFile.Write "MACAddress" & vbtab
objLogFile.Write "IPAddress" & vbtab

objLogFile.Writeline

On Error Resume Next

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")


Set colItems4 = objWMIService.ExecQuery( _
"SELECT * FROM Win32_NetworkAdapterConfiguration",,48)

For Each objItem in colItems4


objLogFile.Write objItem.Caption & vbtab
objLogFile.Write objItem.Description & vbtab
objLogFile.Write objItem.DHCPServer & vbtab
objLogFile.Write objItem.DNSDomain & vbtab
objLogFile.Write objItem.DNSHostName & vbtab
objLogFile.Write objItem.IPXAddress & vbtab
objLogFile.Write objItem.MACAddress & vbtab

If isNull(objItem.IPAddress) Then
objLogFile.Write "" & vbtab
Else
objLogFile.Write Join(objItem.IPAddress, ",") & vbtab
End If

objLogFile.Writeline
Next

If Err.Number <> 0 Then


objLogFile.Writeline
objLogFile.Write "Error WMI: " & Err.Number & vbtab
objLogFile.Write "Error (Hex): " & Hex(Err.Number) & vbtab
objLogFile.Write "Source: " & Err.Source & vbtab
objLogFile.Write "Description: " & Err.Description
objLogFile.Writeline
Err.Clear
End If

objLogFile.Writeline
objLogFile.Write "FIN DE REPORTE"
objLogFile.Writeline

objLogFile.Close

'-------------------------------------------------PRODUCTOS WMI
------------------------------------

strFullName = fullpath & "\" & "05_Prod_" & strFileName & "_" & dateStr
Set objLogFile = objFSO.CreateTextFile(strFullName & ".csv", ForWriting, True)

objLogFile.Writeline
objLogFile.Write "PRODUCTOS VIA WMI"
objLogFile.Writeline

objLogFile.Write "Caption" & vbtab


objLogFile.Write "Vendor" & vbtab
objLogFile.Write "Version" & vbtab
objLogFile.Write "InstallDate" & vbtab
objLogFile.Write "InstallState"

objLogFile.Writeline

On Error Resume Next

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")


Set colItems3 = objWMIService.ExecQuery( _
"SELECT * FROM Win32_Product",,48)

For Each objItem in colItems3


objLogFile.Write objItem.Caption & vbtab
objLogFile.Write objItem.Vendor & vbtab
objLogFile.Write objItem.Version & vbtab
objLogFile.Write objItem.InstallDate & vbtab
objLogFile.Write objItem.InstallState
objLogFile.Writeline
Next

If Err.Number <> 0 Then


objLogFile.Writeline
objLogFile.Write "Error Productos: WMI: " & Err.Number & vbtab
objLogFile.Write "Error (Hex): " & Hex(Err.Number) & vbtab
objLogFile.Write "Source: " & Err.Source & vbtab
objLogFile.Write "Description: " & Err.Description
objLogFile.Writeline
Err.Clear
End If

objLogFile.Writeline
objLogFile.Write "FIN DE REPORTE"
objLogFile.Writeline
objLogFile.Close

'--------------------------------------------PRODUCTOS REGISTRO
------------------------------------

objLogFile.Writeline
objLogFile.Write "PRODCUTOS VIA REGISTRO"
objLogFile.Writeline

objLogFile.Write "Display Name" & vbtab


objLogFile.Write "Display Version" & vbtab
objLogFile.Write "Install Date" & vbtab

objLogFile.Writeline

On Error Resume Next

Set objReg = GetObject("winmgmts://" & strComputer & "/root/default:StdRegProv")

Const strBaseKey = _
"Software\Microsoft\Windows\CurrentVersion\Uninstall\"
objReg.EnumKey HKLM, strBaseKey, arrSubKeys

For Each strSubKey In arrSubKeys

intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, _


"DisplayName", strValue)

intRet2 = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, _


"DisplayVersion", strValue2)

intRet3 = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, _


"InstallDate", strValue3)

If intRet <> 0 Then


intRet = objReg.GetStringValue(HKLM, strBaseKey & strSubKey, _
"QuietDisplayName", strValue)
End If

If (strValue <> "") and (intRet = 0) Then


objLogFile.Write strValue & vbtab
objLogFile.Write strValue2 & vbtab
objLogFile.Write strValue3 & vbtab
objLogFile.Writeline
End If

Next

If Err.Number <> 0 Then


objLogFile.Writeline
objLogFile.Write "Error Productos: Registro: " & Err.Number & vbtab
objLogFile.Write "Error (Hex): " & Hex(Err.Number) & vbtab
objLogFile.Write "Source: " & Err.Source & vbtab
objLogFile.Write "Description: " & Err.Description
objLogFile.Writeline
Err.Clear
End If

objLogFile.Writeline
objLogFile.Write "FIN DE REPORTE"
objLogFile.Writeline

objLogText.Close

WScript.Echo "Inventario Completo"

You might also like