hace 9 años hice un script en .vbs que compartía en una unidad de red y a través de un controlador de dominio mediante políticas de grupo ejecutaba el .vbs cada vez que iniciaba sesión un usuario.
'_________________________________
'Variables de entorno |
'_________________________________
Set objWMIService = GetObject("winmgmts:")
Set objLogicalDisk = objWMIService.Get("Win32_LogicalDisk.DeviceID='c:'")
set name = WScript.CreateObject("WScript.network")
Set fso = CreateObject("Scripting.FileSystemObject")
Set objfso = createobject("scripting.filesystemobject")
Set oShell = CreateObject("wscript.Shell")
Set env = oShell.environment("Process")
strComputer = env.Item("Computername")
'___________________________________
'Impresoras red |
'___________________________________
on error resume Next
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
report = report & objPrinter.Name & "<br/>"
Next
impresoras = report
'___________________________________
'Unidades de red |
'___________________________________
on error resume Next
const bytesToGb = 1073741824
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_MappedLogicalDisk")
For Each objItem in colItems
report1 = report1 & objItem.DeviceID & " -> " & objItem.ProviderName & "<br/>"
next
unidadesred = report1
'___________________________________
'Version Windows |
'___________________________________
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
report2 = report2 & objItem.Caption
Next
winver = report2
'___________________________________
'General PC |
'___________________________________
'nombre del equipo
nombre_equipo = name.computerName
'fecha actual
fecha = Now()
'espacio disponible en disco es la variable freedisk
freedisk = objLogicalDisk.FreeSpace /1024\1024+1
'espacio Total del disco duro
total = objLogicalDisk.Size /1024\1024+1
'nombre del usuario
user = name.USERNAME
'___________________________________
'CPU |
'___________________________________
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colProcessors = objWMIService.ExecQuery("Select * from Win32_Processor")
For Each objProcessor in colProcessors
info = info & objProcessor.Name
next
cpu = info
'___________________________________
'RAM |
'___________________________________
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Computersystem")
For Each Item In colItems
ramm = ramm & Round(Item.TotalPhysicalMemory /1073741824,1)
Next
'___________________________________
'IP de máquina y mascara de red |
'___________________________________
strcomputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")
strCount = 1
For Each objitem in colitems
If strCount = 1 Then
strIPAddress = Join(objitem.IPAddress, "%")
IP = stripaddress
strCount = strCount + 1
Else
End If
next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colAdapters = objWMIService.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled = True")
For Each objAdapter in colAdapters
IPdebut = LBound(objAdapter.IPAddress)
IPfin = UBound(objAdapter.IPAddress)
If (objAdapter.IPAddress(IPdebut) <> "") then
For i = IPdebut To IPfin
If InStr(objAdapter.IPAddress(i),":") = 0 Then msg = msg & ";" & objAdapter.IPSubnet(i) & vbCrLf
mascara = objAdapter.IPSubnet(0)
Next
End If
Next
'en IP tenemos la direccion IP y la MAC juntas, las separaremos con la funcion SPLIT con esta funcion creamos un array. En el indice 0 tendremos la direccion IP y en el indice 1 tendremos la MAC.
direccionIP = Split(IP,"%")
'___________________________________
'Licencia de Windows |
'___________________________________
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From SoftwareLicensingProduct")
Coltest = int(0)
IsWinActivated = True
For Each objitem In colItems
IF int(objitem.GracePeriodRemaining) = 0 Then Coltest = True else Coltest = False
IF Coltest = False then IsWinActivated = False
Next
IF IsWinActivated = False then
licencia = "Windows no activado"
ELSE
licencia = "windows activado"
END IF
Tira de WMI Service supongo que se podrá acceder a esta clase de windows desde powershell.
*El código que paso muestra como se generan las variables con los valores, pero ni los imprime, ni los guarda en un fichero. En el script original los guardaba en un fichero, pero me ha dado pereza ocultar rutas y nombres así que pongo solo el cacho donde generaba las consultas para cada dato.