Corrige detecção de ativação do Windows

This commit is contained in:
Esdras Renan 2025-10-13 19:34:45 -03:00
parent 2f47c40894
commit 26ae2aa8e5

View file

@ -693,8 +693,10 @@ fn collect_windows_extended() -> serde_json::Value {
// Informações de build/edição e ativação // Informações de build/edição e ativação
let os_info = ps(r#" let os_info = ps(r#"
$cv = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion'; $cv = Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion';
$ls = Get-CimInstance -Query "SELECT Name, LicenseStatus FROM SoftwareLicensingProduct WHERE PartialProductKey IS NOT NULL" | Where-Object { $_.Name -like 'Windows*' } | Select-Object -First 1; $lsItems = Get-CimInstance -Query "SELECT Name, LicenseStatus, PartialProductKey FROM SoftwareLicensingProduct WHERE PartialProductKey IS NOT NULL" | Where-Object { $_.Name -like 'Windows*' };
$lsCode = if ($ls -and $ls.LicenseStatus -ne $null) { [int]$ls.LicenseStatus } else { 0 }; $activatedItem = $lsItems | Where-Object { $_.LicenseStatus -eq 1 } | Select-Object -First 1;
$primaryItem = if ($activatedItem) { $activatedItem } else { $lsItems | Select-Object -First 1 };
$lsCode = if ($primaryItem -and $primaryItem.LicenseStatus -ne $null) { [int]$primaryItem.LicenseStatus } else { 0 };
[PSCustomObject]@{ [PSCustomObject]@{
ProductName = $cv.ProductName ProductName = $cv.ProductName
CurrentBuild = $cv.CurrentBuild CurrentBuild = $cv.CurrentBuild
@ -703,7 +705,7 @@ fn collect_windows_extended() -> serde_json::Value {
ReleaseId = $cv.ReleaseId ReleaseId = $cv.ReleaseId
EditionID = $cv.EditionID EditionID = $cv.EditionID
LicenseStatus = $lsCode LicenseStatus = $lsCode
IsActivated = ($lsCode -eq 1) IsActivated = ($activatedItem -ne $null)
} }
"#).unwrap_or_else(|| json!({})); "#).unwrap_or_else(|| json!({}));