Fix activation check
This commit is contained in:
@@ -27,13 +27,11 @@ function CheckOfficeInstall {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function CheckActivation {
|
function CheckActivation {
|
||||||
$osLicense = Get-CimInstance -ClassName SoftwareLicensingProduct | Where-Object { $_.Description -match "Windows" }
|
$osLicense = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" | where { $_.PartialProductKey } | select Description, LicenseStatus
|
||||||
$officeLicense = Get-CimInstance -ClassName SoftwareLicensingProduct | Where-Object { $_.Description -match "Office" }
|
$officeLicense = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Office%'" | where { $_.PartialProductKey } | select Description, LicenseStatus
|
||||||
$windows = $osLicense.Description
|
|
||||||
$office = $officeLicense.Description
|
|
||||||
|
|
||||||
# if both activated return true
|
# if both activated return true
|
||||||
if ($osLicense.LicenseStatus -eq 1 -and $officeLicense.LicenseStatus -eq 1) {
|
if ($osLicense.LicenseStatus -eq 1 -and $officeLicense.LicenseStatus -eq 2) {
|
||||||
Write-Host "Windows and Office are activated."
|
Write-Host "Windows and Office are activated."
|
||||||
return $true
|
return $true
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
23
setupReg.ps1
23
setupReg.ps1
@@ -87,27 +87,8 @@ function SetupEleveReg {
|
|||||||
}
|
}
|
||||||
Write-Host "Added registry entries"
|
Write-Host "Added registry entries"
|
||||||
Write-Host "Unloading registry HIVE"
|
Write-Host "Unloading registry HIVE"
|
||||||
$retryCount = 0
|
Write-Host "REG UNLOAD HKEY_USERS\$UserSID"
|
||||||
$retryLimit = 5
|
Start-Process powershell.exe -ArgumentList "REG UNLOAD HKEY_USERS\$UserSID" -WindowStyle Hidden
|
||||||
$success = $false
|
|
||||||
|
|
||||||
while (-not $success -and $retryCount -lt $retryLimit) {
|
|
||||||
Start-Sleep -s 5
|
|
||||||
Write-Host "REG UNLOAD HKEY_USERS\$UserSID (attempt $($retryCount + 1))"
|
|
||||||
$res = REG UNLOAD HKEY_USERS\$UserSID
|
|
||||||
if ($res -ne 0) {
|
|
||||||
Write-Host "Failed to unload $username's HKU registry hive. Retrying in 5 seconds..."
|
|
||||||
$retryCount++
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Write-Host "Unloaded $username's HKU registry hive."
|
|
||||||
$success = $true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (-not $success) {
|
|
||||||
Write-Host "Failed to unload $username's HKU registry hive after $retryLimit attempts."
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Write-Host "Unable to get the user's HKU registry."
|
Write-Host "Unable to get the user's HKU registry."
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user