eccoci qui di nuovo a parlare di scripting e di automazione windows.
Oggi vediamo come sia possibile ottenere il Serial Number, il produttore, il produttore della BIOS, ed altre interessanti informazioni direttamente da windows con un piccolo script, che interpella le proprietà della BIOS con vbscript.
Ecco qui lo script.
const ForWriting = 2
set Dic = createObject("Scripting.dictionary")
Set objFSO = createObject("Scripting.FilesystemObject")
Set oShell = CreateObject("Wscript.Shell")
Set varAmbientali =
oShell.Environment("PROCESS")
nomecomputer = varAmbientali("COMPUTERNAME")
fileLog = nomecomputer & "_info.txt"
Set objFileLog = objFSO.OpenTextFile(fileLog,
ForWriting, True)
strComputer = "."
Set objWMIService =
GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colBIOS =
objWMIService.ExecQuery _
("Select * from Win32_BIOS")
Set objB =
objWMIService.Get("Win32_BIOS").Spawninstance_
for each objProp in objB.Properties_
dim objProp
Dic.Add objProp.Name, ""
REM wscript.echo objProp.Name & ": " & " - tipo:
" & TypeName(objProp) & "- Array : " & objProp.value
REM for each objPP in objProp
REM For i = 0 to Ubound(objBIOS.BIOSVersion)
REM wscript.echo ObjB.Properties_(objProp.Name)(i)
REM next
REM next
next
REM for each strPName in Dic.Keys
REM wscript.echo strPName & ": " &
objB.Properties_(strPName).Value
REM next
For each objBIOS in colBIOS
for each strPName in Dic.Keys
REM wscript.echo strPName
REM strCodeT = "wscript.echo strPName &
"" - "" & typeName(objBIOS." & strPName &
")"
REM execute strCodeT
strCode = "t = typeName(objBIOS." & strPName & ")"
executeGlobal strCode
select case t
Case "String"
strCode1 = "objFileLog.WriteLine strPName & "":
"" & objBIOS." &
strPName
Case "Boolean"
strCode1 = "objFileLog.WriteLine strPName & "":
"" & objBIOS." &
strPName
Case "Date"
strCode1 = "objFileLog.WriteLine strPName & "":
"" & objBIOS." &
strPName
Case "Int"
strCode1 = "objFileLog.WriteLine strPName & "":
"" & objBIOS." &
strPName
Case "Long"
strCode1 = "objFileLog.WriteLine strPName & "":
"" & objBIOS." &
strPName
Case "Variant()"
strCode1 = "For i = 0 to Ubound(objBIOS." & strPName & ")" &
vbCrLf & "objFileLog.WriteLine
strPName & "": "" & objBIOS." & strPName & "(i)" &
vbCrLf & "Next"
Case Else
strCode1 = "objFileLog.WriteLine strPName & "":
"" "
end select
executeGlobal strCode1
REM wscript.echo strPName & ": " &
objBIOS.
next
REM objFileLog.WriteLine "Caption: " & objBIOS.Caption
REM objFileLog.WriteLine "Build Number: " &
objBIOS.BuildNumber
REM objFileLog.WriteLine "Current Language: " &
objBIOS.CurrentLanguage
REM objFileLog.WriteLine "Installable Languages: " &
objBIOS.InstallableLanguages
REM objFileLog.WriteLine "Manufacturer: " &
objBIOS.Manufacturer
REM objFileLog.WriteLine "Name: " & objBIOS.Name
REM objFileLog.WriteLine "Caption: " & objBIOS.Caption
REM objFileLog.WriteLine "Description: " &
objBIOS.Description
REM objFileLog.WriteLine "IdentificationCode: " &
objBIOS.IdentificationCode
REM objFileLog.WriteLine "InstallableLanguages: " &
objBIOS.InstallableLanguages
REM objFileLog.WriteLine "InstallDate: " &
objBIOS.InstallDate
REM objFileLog.WriteLine "Primary BIOS: " &
objBIOS.PrimaryBIOS
REM objFileLog.WriteLine "Release Date: " &
objBIOS.ReleaseDate
REM objFileLog.WriteLine "Serial Number: " &
objBIOS.SerialNumber
REM objFileLog.WriteLine "SMBIOS Version: " & objBIOS.SMBIOSBIOSVersion
REM objFileLog.WriteLine "SMBIOS Major Version: " &
objBIOS.SMBIOSMajorVersion
REM objFileLog.WriteLine "SMBIOS Minor Version: " &
objBIOS.SMBIOSMinorVersion
REM objFileLog.WriteLine "SMBIOS Present: " &
objBIOS.SMBIOSPresent
REM objFileLog.WriteLine "Status: " & objBIOS.Status
REM objFileLog.WriteLine "Version: " & objBIOS.Version
REM For i = 0 to Ubound(objBIOS.BIOSVersion)
REM objFileLog.WriteLine "BIOS Version: " &
_
REM objBIOS.BIOSVersion(i)
REM Next
REM For i = 0 to Ubound(objBIOS.BiosCharacteristics)
REM objFileLog.WriteLine "BIOS Characteristics:
" & _
REM objBIOS.BiosCharacteristics(i)
REM Next
Next
In pratica, utilizzando WMI (Windows Management Instrumentation), leggiamo le proprietà possibili della BIOS in un dictionary object e quindi le interroghiamo poi per ogni istanza di BIOS trovata nel sistema (solitamente solo 1 :-) ), a questo punto "componiamo" delle stringhe comando, in base alle casistiche in cui ci troviamo, per rendere leggibile il tutto e poi scriviamo in un file che ha nome del computer.
Happy Scripting!
Nessun commento:
Posta un commento
I commenti sono soggetti a moderazione, prima di essere pubblicati.
Qualsiasi contenuto illecito, immorale o che io ritenga (arbitrariamente) offensivo od inappropriato, verrà cancellato.