2024-07-13 04:46:38 +05:30
@ echo off
: : Check-Activation-Status
: : Written by @abbodi1406
: : https://gravesoft.dev/cas
2024-08-18 05:08:35 +05:30
: : Set Environment variables, it helps if they are misconfigured in the system
setlocal EnableExtensions
setlocal DisableDelayedExpansion
set " PathExt=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC "
set " SysPath= %SystemRoot% \System32 "
2024-07-13 04:46:38 +05:30
set " Path= %SystemRoot% \System32; %SystemRoot% ; %SystemRoot% \System32\Wbem; %SystemRoot% \System32\WindowsPowerShell\v1.0\ "
if exist " %SystemRoot% \Sysnative\reg.exe " (
2024-08-18 05:08:35 +05:30
set " SysPath= %SystemRoot% \Sysnative "
2024-07-13 04:46:38 +05:30
set " Path= %SystemRoot% \Sysnative; %SystemRoot% ; %SystemRoot% \Sysnative\Wbem; %SystemRoot% \Sysnative\WindowsPowerShell\v1.0\; %Path% "
)
2024-08-18 05:08:35 +05:30
set " ComSpec= %SysPath% \cmd.exe "
set " PSModulePath= %ProgramFiles% \WindowsPowerShell\Modules; %SysPath% \WindowsPowerShell\v1.0\Modules "
2024-07-13 04:46:38 +05:30
set " _psc=powershell -nop -c "
set " _err===== ERROR ==== "
set _pwsh = 1
for %% # in ( powershell.exe) do @ if " %% ~$PATH:# " == " " set _pwsh = 0
cmd /c " %_psc% " $ExecutionContext.SessionState.LanguageMode" " | find /i " FullLanguage " 1 > nul || ( set _pwsh = 0)
if %_pwsh% equ 0 (
echo %_err%
cmd /c " %_psc% " $ExecutionContext.SessionState.LanguageMode" "
echo Windows PowerShell is not working correctly.
echo It is required for this script to work.
goto : E_Exit
)
set " _batf= %~f0 "
set " _batp= %_batf:'=''% "
setlocal EnableDelayedExpansion
%_psc% " $f=[IO.File]::ReadAllText('!_batp!') -split ':sppmgr\:.*';iex ($f[1]) "
: E_Exit
echo .
2024-08-18 05:08:35 +05:30
echo Press 0 key to exit.
choice /c 0 /n
2024-07-13 04:46:38 +05:30
exit /b
: sppmgr :
2025-01-30 02:25:04 +05:30
param (
[Parameter()]
[switch]
$All,
[Parameter()]
[switch]
$Dlv,
[Parameter()]
[switch]
$IID,
[Parameter()]
[switch]
$Pass
)
function CONOUT($strObj)
{
Out-Host -Input $strObj
}
2024-07-13 04:46:38 +05:30
function ExitScript($ExitCode = 0)
{
Exit $ExitCode
}
if (-Not $ P S V e r s i o n T a b l e ) {
2025-01-30 02:25:04 +05:30
" ==== ERROR ====`r`n "
" Windows PowerShell 1.0 is not supported by this script. "
2024-07-13 04:46:38 +05:30
ExitScript 1
}
if ($ExecutionContext.SessionState.LanguageMode.value__ - N E 0 ) {
2025-01-30 02:25:04 +05:30
" ==== ERROR ====`r`n "
" Windows PowerShell is not running in Full Language Mode. "
2024-07-13 04:46:38 +05:30
ExitScript 1
}
$winbuild = 1
try {
$winbuild = [System.Diagnostics.FileVersionInfo]::GetVersionInfo(" $env:SystemRoot\System32\kernel32.dll " ).FileBuildPart
} catch {
2025-01-30 02:25:04 +05:30
$winbuild = [int]([wmi]'Win32_OperatingSystem=@').BuildNumber
2024-07-13 04:46:38 +05:30
}
if ($winbuild - E Q 1 ) {
2025-01-30 02:25:04 +05:30
" ==== ERROR ====`r`n "
" Could not detect Windows build. "
2024-07-13 04:46:38 +05:30
ExitScript 1
}
if ($winbuild - L T 2 6 0 0 ) {
2025-01-30 02:25:04 +05:30
" ==== ERROR ====`r`n "
" This build of Windows is not supported by this script. "
ExitScript 1
}
$SysPath = " $env:SystemRoot\System32 "
if (Test-Path " $ e n v : S y s t e m R o o t \ S y s n a t i v e \ r e g . e x e " ) {
$SysPath = " $env:SystemRoot\Sysnative "
}
if (Test-Path " $ S y s P a t h \ s p p c . d l l " ) {
$SLdll = 'sppc.dll'
} elseif (Test-Path " $SysPath\slc.dll " ) {
$SLdll = 'slc.dll'
} else {
" ==== ERROR ====`r`n "
" Software Licensing Client Dll is not detected. "
2024-07-13 04:46:38 +05:30
ExitScript 1
}
2025-01-30 02:25:04 +05:30
if ($All.IsPresent)
{
$isAll = {CONOUT " `r " }
$noAll = {$null}
}
else
{
$isAll = {$null}
$noAll = {CONOUT " `r " }
}
$Dlv = $Dlv.IsPresent
$IID = $IID.IsPresent -Or $Dlv.IsPresent
2024-07-13 04:46:38 +05:30
$NT6 = $winbuild -GE 6000
$NT7 = $winbuild -GE 7600
$NT9 = $winbuild -GE 9600
$Admin = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
$line2 = " ============================================================ "
$line3 = " ____________________________________________________________ "
2025-01-30 02:25:04 +05:30
function UnQuickEdit
{
$t=[AppDomain]::CurrentDomain.DefineDynamicAssembly((Get-Random), 1).DefineDynamicModule((Get-Random), $False).DefineType((Get-Random))
$t.DefinePInvokeMethod('GetStdHandle', 'kernel32.dll', 22, 1, [IntPtr], @([Int32]), 1, 3).SetImplementationFlags(128)
$t.DefinePInvokeMethod('SetConsoleMode', 'kernel32.dll', 22, 1, [Boolean], @([IntPtr], [Int32]), 1, 3).SetImplementationFlags(128)
$t.DefinePInvokeMethod('GetConsoleWindow', 'kernel32.dll', 22, 1, [IntPtr], @(), 1, 3).SetImplementationFlags(128)
$t.DefinePInvokeMethod('SendMessageW', 'user32.dll', 22, 1, [IntPtr], @([IntPtr], [UInt32], [IntPtr], [IntPtr]), 1, 3).SetImplementationFlags(128)
$k=$t.CreateType()
if ($winbuild - G E 1 7 7 6 3 ) {
if ($k::SendMessageW($k::GetConsoleWindow(), 1 2 7 , 0 , 0 ) - E Q [ I n t P t r ] : : Z e r o ) {
return
}
}
$v=(0x0080, 0x00A0)[!($winbuild -GE 10586)]
$b=$k::SetConsoleMode($k::GetStdHandle(-10), $v)
}
2024-07-13 04:46:38 +05:30
function echoWindows
{
2025-01-30 02:25:04 +05:30
CONOUT " $line2 "
CONOUT " === Windows Status === "
CONOUT " $line2 "
& $noAll
2024-07-13 04:46:38 +05:30
}
function echoOffice
{
if ($doMSG - E Q 0 ) {
return
}
2025-01-30 02:25:04 +05:30
& $isAll
CONOUT " $line2 "
CONOUT " === Office Status === "
CONOUT " $line2 "
& $noAll
2024-07-13 04:46:38 +05:30
$script:doMSG = 0
}
function strGetRegistry($strKey, $strName)
{
2025-01-30 02:25:04 +05:30
try {
return [Microsoft.Win32.Registry]::GetValue($strKey, $strName, $null)
} catch {
return $null
}
2024-07-13 04:46:38 +05:30
}
function CheckOhook
{
$ohook = 0
$paths = " ${env:ProgramFiles} " , " ${env:ProgramW6432} " , " ${env:ProgramFiles(x86)} "
15, 16 | foreach `
{
$A = $_; $paths | foreach `
{
if (Test-Path " $ ( $ _ ) $ ( ' \ M i c r o s o f t O f f i c e \ O f f i c e ' ) $ ( $ A ) $ ( ' \ s p p c * d l l ' ) " ) { $ o h o o k = 1 }
}
}
" System " , " SystemX86 " | foreach `
{
$A = $_; " Office 15 " , " Office " | foreach `
{
$B = $_; $paths | foreach `
{
if (Test-Path " $ ( $ _ ) $ ( ' \ M i c r o s o f t ' ) $ ( $ B ) $ ( ' \ r o o t \ v f s \ ' ) $ ( $ A ) $ ( ' \ s p p c * d l l ' ) " ) { $ o h o o k = 1 }
}
}
}
if ($ohook - E Q 0 ) {
return
}
2025-01-30 02:25:04 +05:30
& $isAll
CONOUT " $line2 "
CONOUT " === Office Ohook Status === "
CONOUT " $line2 "
$host.UI.WriteLine('Yellow', 'Black', " `r`nOhook for permanent Office activation is installed.`r`nYou can ignore the below mentioned Office activation status. " )
& $noAll
2024-07-13 04:46:38 +05:30
}
#region WMI
2025-01-30 02:25:04 +05:30
function DetectID($strSLP, $strAppId)
2024-07-13 04:46:38 +05:30
{
2025-01-30 02:25:04 +05:30
$ppk = (" AND PartialProductKey <> NULL) " , " ) " )[$All.IsPresent]
$fltr = " SELECT ID FROM $strSLP WHERE (ApplicationID='$strAppId' "
$clause = $fltr + $ppk
$sWmi = [wmisearcher]$clause
$sWmi.Options.Rewindable = $false
return ($sWmi.Get().Count -GT 0)
2024-07-13 04:46:38 +05:30
}
2025-01-30 02:25:04 +05:30
function GetID($strSLP, $strAppId)
2024-07-13 04:46:38 +05:30
{
$NT5 = ($strSLP -EQ $wslp -And $winbuild -LT 6001)
$IDs = [Collections.ArrayList]@()
2025-01-30 02:25:04 +05:30
$isAdd = (" AND LicenseDependsOn <> NULL) " , " ) " )[$NT5]
$noAdd = " AND LicenseDependsOn IS NULL) "
$query = " SELECT ID FROM $strSLP WHERE (ApplicationID='$strAppId' AND PartialProductKey "
2024-07-13 04:46:38 +05:30
if ($All.IsPresent) {
2025-01-30 02:25:04 +05:30
$fltr = $query + " IS NULL "
$clause = $fltr + $isAdd
$sWmi = [wmisearcher]$clause
$sWmi.Options.Rewindable = $false
try {$sWmi.Get() | select -Expand Properties -EA 0 | foreach {$IDs += $_.Value}} catch {}
2024-07-13 04:46:38 +05:30
if (-Not $ N T 5 ) {
2025-01-30 02:25:04 +05:30
$clause = $fltr + $noAdd
$sWmi = [wmisearcher]$clause
$sWmi.Options.Rewindable = $false
try {$sWmi.Get() | select -Expand Properties -EA 0 | foreach {$IDs += $_.Value}} catch {}
2024-07-13 04:46:38 +05:30
}
}
2025-01-30 02:25:04 +05:30
$fltr = $query + " <> NULL "
$clause = $fltr + $isAdd
$sWmi = [wmisearcher]$clause
$sWmi.Options.Rewindable = $false
try {$sWmi.Get() | select -Expand Properties -EA 0 | foreach {$IDs += $_.Value}} catch {}
2024-07-13 04:46:38 +05:30
if (-Not $ N T 5 ) {
2025-01-30 02:25:04 +05:30
$clause = $fltr + $noAdd
$sWmi = [wmisearcher]$clause
$sWmi.Options.Rewindable = $false
try {$sWmi.Get() | select -Expand Properties -EA 0 | foreach {$IDs += $_.Value}} catch {}
2024-07-13 04:46:38 +05:30
}
return $IDs
}
function DetectSubscription {
if ($null - E Q $ o b j S v c . S u b s c r i p t i o n T y p e - O r $ o b j S v c . S u b s c r i p t i o n T y p e - E Q 1 2 0 ) {
return
}
if ($objSvc.SubscriptionType - E Q 1 ) {
$SubMsgType = " Device based "
} else {
$SubMsgType = " User based "
}
if ($objSvc.SubscriptionStatus - E Q 1 2 0 ) {
$SubMsgStatus = " Expired "
} elseif ($objSvc.SubscriptionStatus -EQ 100) {
$SubMsgStatus = " Disabled "
} elseif ($objSvc.SubscriptionStatus -EQ 1) {
$SubMsgStatus = " Active "
} else {
$SubMsgStatus = " Not active "
}
$SubMsgExpiry = " Unknown "
if ($objSvc.SubscriptionExpiry) {
if ($objSvc.SubscriptionExpiry.Contains(" unspecified " ) - E Q $ f a l s e ) { $ S u b M s g E x p i r y = $ o b j S v c . S u b s c r i p t i o n E x p i r y }
}
$SubMsgEdition = " Unknown "
if ($objSvc.SubscriptionEdition) {
if ($objSvc.SubscriptionEdition.Contains(" UNKNOWN " ) - E Q $ f a l s e ) { $ S u b M s g E d i t i o n = $ o b j S v c . S u b s c r i p t i o n E d i t i o n }
}
2025-01-30 02:25:04 +05:30
CONOUT " `nSubscription information: "
CONOUT " Edition: $SubMsgEdition "
CONOUT " Type : $SubMsgType "
CONOUT " Status : $SubMsgStatus "
CONOUT " Expiry : $SubMsgExpiry "
}
function DetectAdbaClient
{
CONOUT " `nAD Activation client information: "
CONOUT " Object Name: $ADActivationObjectName "
CONOUT " Domain Name: $ADActivationObjectDN "
CONOUT " CSVLK Extended PID: $ADActivationCsvlkPid "
CONOUT " CSVLK Activation ID: $ADActivationCsvlkSkuId "
2024-07-13 04:46:38 +05:30
}
function DetectAvmClient
{
2025-01-30 02:25:04 +05:30
CONOUT " `nAutomatic VM Activation client information: "
2024-07-13 04:46:38 +05:30
if (-Not [ S t r i n g ] : : I s N u l l O r E m p t y ( $ I A I D ) ) {
2025-01-30 02:25:04 +05:30
CONOUT " Guest IAID: $IAID "
2024-07-13 04:46:38 +05:30
} else {
2025-01-30 02:25:04 +05:30
CONOUT " Guest IAID: Not Available "
2024-07-13 04:46:38 +05:30
}
if (-Not [ S t r i n g ] : : I s N u l l O r E m p t y ( $ A u t o m a t i c V M A c t i v a t i o n H o s t M a c h i n e N a m e ) ) {
2025-01-30 02:25:04 +05:30
CONOUT " Host machine name: $AutomaticVMActivationHostMachineName "
2024-07-13 04:46:38 +05:30
} else {
2025-01-30 02:25:04 +05:30
CONOUT " Host machine name: Not Available "
2024-07-13 04:46:38 +05:30
}
if ($AutomaticVMActivationLastActivationTime.Substring(0, 4 ) - N E " 1 6 0 1 " ) {
$EED = [DateTime]::Parse([Management.ManagementDateTimeConverter]::ToDateTime($AutomaticVMActivationLastActivationTime),$null,48).ToString('yyyy-MM-dd hh:mm:ss tt')
2025-01-30 02:25:04 +05:30
CONOUT " Activation time: $EED UTC "
2024-07-13 04:46:38 +05:30
} else {
2025-01-30 02:25:04 +05:30
CONOUT " Activation time: Not Available "
2024-07-13 04:46:38 +05:30
}
if (-Not [ S t r i n g ] : : I s N u l l O r E m p t y ( $ A u t o m a t i c V M A c t i v a t i o n H o s t D i g i t a l P i d 2 ) ) {
2025-01-30 02:25:04 +05:30
CONOUT " Host Digital PID2: $AutomaticVMActivationHostDigitalPid2 "
2024-07-13 04:46:38 +05:30
} else {
2025-01-30 02:25:04 +05:30
CONOUT " Host Digital PID2: Not Available "
2024-07-13 04:46:38 +05:30
}
}
function DetectKmsHost
{
if ($Vista - O r $ N T 5 ) {
$KeyManagementServiceListeningPort = strGetRegistry $SLKeyPath " KeyManagementServiceListeningPort "
$KeyManagementServiceDnsPublishing = strGetRegistry $SLKeyPath " DisableDnsPublishing "
$KeyManagementServiceLowPriority = strGetRegistry $SLKeyPath " EnableKmsLowPriority "
if (-Not $ K e y M a n a g e m e n t S e r v i c e D n s P u b l i s h i n g ) { $ K e y M a n a g e m e n t S e r v i c e D n s P u b l i s h i n g = " T R U E " }
if (-Not $ K e y M a n a g e m e n t S e r v i c e L o w P r i o r i t y ) { $ K e y M a n a g e m e n t S e r v i c e L o w P r i o r i t y = " F A L S E " }
} else {
$KeyManagementServiceListeningPort = $objSvc.KeyManagementServiceListeningPort
$KeyManagementServiceDnsPublishing = $objSvc.KeyManagementServiceDnsPublishing
$KeyManagementServiceLowPriority = $objSvc.KeyManagementServiceLowPriority
}
if (-Not $ K e y M a n a g e m e n t S e r v i c e L i s t e n i n g P o r t ) { $ K e y M a n a g e m e n t S e r v i c e L i s t e n i n g P o r t = 1 6 8 8 }
if ($KeyManagementServiceDnsPublishing - E Q " T R U E " ) {
$KeyManagementServiceDnsPublishing = " Enabled "
} else {
$KeyManagementServiceDnsPublishing = " Disabled "
}
if ($KeyManagementServiceLowPriority - E Q " T R U E " ) {
$KeyManagementServiceLowPriority = " Low "
} else {
$KeyManagementServiceLowPriority = " Normal "
}
2025-01-30 02:25:04 +05:30
CONOUT " `nKey Management Service host information: "
CONOUT " Current count: $KeyManagementServiceCurrentCount "
CONOUT " Listening on Port: $KeyManagementServiceListeningPort "
CONOUT " DNS publishing: $KeyManagementServiceDnsPublishing "
CONOUT " KMS priority: $KeyManagementServiceLowPriority "
2024-07-13 04:46:38 +05:30
if (-Not [ S t r i n g ] : : I s N u l l O r E m p t y ( $ K e y M a n a g e m e n t S e r v i c e T o t a l R e q u e s t s ) ) {
2025-01-30 02:25:04 +05:30
CONOUT " `nKey Management Service cumulative requests received from clients: "
CONOUT " Total: $KeyManagementServiceTotalRequests "
CONOUT " Failed: $KeyManagementServiceFailedRequests "
CONOUT " Unlicensed: $KeyManagementServiceUnlicensedRequests "
CONOUT " Licensed: $KeyManagementServiceLicensedRequests "
CONOUT " Initial grace period: $KeyManagementServiceOOBGraceRequests "
CONOUT " Expired or Hardware out of tolerance: $KeyManagementServiceOOTGraceRequests "
CONOUT " Non-genuine grace period: $KeyManagementServiceNonGenuineGraceRequests "
if ($null - N E $ K e y M a n a g e m e n t S e r v i c e N o t i f i c a t i o n R e q u e s t s ) { C O N O U T " N o t i f i c a t i o n : $ K e y M a n a g e m e n t S e r v i c e N o t i f i c a t i o n R e q u e s t s " }
2024-07-13 04:46:38 +05:30
}
}
function DetectKmsClient
{
2025-01-30 02:25:04 +05:30
if ($null - N E $ V L A c t i v a t i o n T y p e E n a b l e d ) { C O N O U T " C o n f i g u r e d A c t i v a t i o n T y p e : $ ( $ V L A c t T y p e s [ $ V L A c t i v a t i o n T y p e E n a b l e d ] ) " }
CONOUT " `r "
2024-07-13 04:46:38 +05:30
if ($LicenseStatus - N E 1 ) {
2025-01-30 02:25:04 +05:30
CONOUT " Please activate the product in order to update KMS client information values. "
2024-07-13 04:46:38 +05:30
return
}
if ($Vista) {
$KeyManagementServicePort = strGetRegistry $SLKeyPath " KeyManagementServicePort "
$DiscoveredKeyManagementServiceMachineName = strGetRegistry $NSKeyPath " DiscoveredKeyManagementServiceName "
$DiscoveredKeyManagementServiceMachinePort = strGetRegistry $NSKeyPath " DiscoveredKeyManagementServicePort "
}
if ([String]::IsNullOrEmpty($KeyManagementServiceMachine)) {
$KmsReg = $null
} else {
if (-Not $ K e y M a n a g e m e n t S e r v i c e P o r t ) { $ K e y M a n a g e m e n t S e r v i c e P o r t = 1 6 8 8 }
$KmsReg = " Registered KMS machine name: ${KeyManagementServiceMachine}:${KeyManagementServicePort} "
}
if ([String]::IsNullOrEmpty($DiscoveredKeyManagementServiceMachineName)) {
$KmsDns = " DNS auto-discovery: KMS name not available "
if ($Vista - A n d - N o t $ A d m i n ) { $ K m s D n s = " D N S a u t o - d i s c o v e r y : R u n t h e s c r i p t a s a d m i n i s t r a t o r t o r e t r i e v e i n f o " }
} else {
if (-Not $ D i s c o v e r e d K e y M a n a g e m e n t S e r v i c e M a c h i n e P o r t ) { $ D i s c o v e r e d K e y M a n a g e m e n t S e r v i c e M a c h i n e P o r t = 1 6 8 8 }
$KmsDns = " KMS machine name from DNS: ${DiscoveredKeyManagementServiceMachineName}:${DiscoveredKeyManagementServiceMachinePort} "
}
if ($null - N E $ o b j S v c . K e y M a n a g e m e n t S e r v i c e H o s t C a c h i n g ) {
if ($objSvc.KeyManagementServiceHostCaching - E Q " T R U E " ) {
$KeyManagementServiceHostCaching = " Enabled "
} else {
$KeyManagementServiceHostCaching = " Disabled "
}
}
2025-01-30 02:25:04 +05:30
CONOUT " Key Management Service client information: "
CONOUT " Client Machine ID (CMID): $($objSvc.ClientMachineID) "
2024-07-13 04:46:38 +05:30
if ($null - E Q $ K m s R e g ) {
2025-01-30 02:25:04 +05:30
CONOUT " $KmsDns "
CONOUT " Registered KMS machine name: KMS name not available "
2024-07-13 04:46:38 +05:30
} else {
2025-01-30 02:25:04 +05:30
CONOUT " $KmsReg "
}
if ($null - N E $ D i s c o v e r e d K e y M a n a g e m e n t S e r v i c e M a c h i n e I p A d d r e s s ) { C O N O U T " K M S m a c h i n e I P a d d r e s s : $ D i s c o v e r e d K e y M a n a g e m e n t S e r v i c e M a c h i n e I p A d d r e s s " }
CONOUT " KMS machine extended PID: $KeyManagementServiceProductKeyID "
CONOUT " Activation interval: $VLActivationInterval minutes "
CONOUT " Renewal interval: $VLRenewalInterval minutes "
if ($null - N E $ K e y M a n a g e m e n t S e r v i c e H o s t C a c h i n g ) { C O N O U T " K M S h o s t c a c h i n g : $ K e y M a n a g e m e n t S e r v i c e H o s t C a c h i n g " }
if (-Not [ S t r i n g ] : : I s N u l l O r E m p t y ( $ K e y M a n a g e m e n t S e r v i c e L o o k u p D o m a i n ) ) { C O N O U T " K M S S R V r e c o r d l o o k u p d o m a i n : $ K e y M a n a g e m e n t S e r v i c e L o o k u p D o m a i n " }
2024-07-13 04:46:38 +05:30
}
function GetResult($strSLP, $strSLS, $strID)
{
2025-01-30 02:25:04 +05:30
try
{
$objPrd = [wmisearcher]" SELECT * FROM $strSLP WHERE ID='$strID' "
$objPrd.Options.Rewindable = $false
$objPrd.Get() | select -Expand Properties -EA 0 | foreach { if (-Not [String]::IsNullOrEmpty($_.Value)) {set $_.Name $_.Value} }
$objPrd.Dispose()
}
catch
{
return
2024-07-13 04:46:38 +05:30
}
$winID = ($ApplicationID -EQ $winApp)
$winPR = ($winID -And -Not $LicenseIsAddon)
$Vista = ($winID -And $NT6 -And -Not $NT7)
$NT5 = ($strSLP -EQ $wslp -And $winbuild -LT 6001)
2025-01-30 02:25:04 +05:30
$reapp = (" Windows " , " App " )[!$winID]
$prmnt = (" machine " , " product " )[!$winPR]
2024-07-13 04:46:38 +05:30
if ($Description | S e l e c t - S t r i n g " V O L U M E _ K M S C L I E N T " ) { $ c K m s C l i e n t = 1 ; $ _ m T a g = " V o l u m e " }
if ($Description | S e l e c t - S t r i n g " T I M E B A S E D _ " ) { $ c T b l C l i e n t = 1 ; $ _ m T a g = " T i m e b a s e d " }
if ($Description | S e l e c t - S t r i n g " V I R T U A L _ M A C H I N E _ A C T I V A T I O N " ) { $ c A v m C l i e n t = 1 ; $ _ m T a g = " A u t o m a t i c V M " }
if ($null - E Q $ c K m s C l i e n t ) {
if ($Description | S e l e c t - S t r i n g " V O L U M E _ K M S " ) { $ c K m s H o s t = 1 }
}
$_gpr = [Math]::Round($GracePeriodRemaining/1440)
if ($_gpr - G T 0 ) {
$_xpr = [DateTime]::Now.addMinutes($GracePeriodRemaining).ToString('yyyy-MM-dd hh:mm:ss tt')
}
if ($null - E Q $ L i c e n s e S t a t u s R e a s o n ) { $ L i c e n s e S t a t u s R e a s o n = - 1 }
$LicenseReason = '0x{0:X}' -f $LicenseStatusReason
$LicenseMsg = " Time remaining: $GracePeriodRemaining minute(s) ($_gpr day(s)) "
if ($LicenseStatus - E Q 0 ) {
$LicenseInf = " Unlicensed "
$LicenseMsg = $null
}
if ($LicenseStatus - E Q 1 ) {
$LicenseInf = " Licensed "
$LicenseMsg = $null
if ($GracePeriodRemaining - E Q 0 ) {
2025-01-30 02:25:04 +05:30
$ExpireMsg = " The $prmnt is permanently activated. "
2024-07-13 04:46:38 +05:30
} else {
$LicenseMsg = " $_mTag activation expiration: $GracePeriodRemaining minute(s) ($_gpr day(s)) "
if ($null - N E $ _ x p r ) { $ E x p i r e M s g = " $ _ m T a g a c t i v a t i o n w i l l e x p i r e $ _ x p r " }
}
}
if ($LicenseStatus - E Q 2 ) {
$LicenseInf = " Initial grace period "
if ($null - N E $ _ x p r ) { $ E x p i r e M s g = " I n i t i a l g r a c e p e r i o d e n d s $ _ x p r " }
}
if ($LicenseStatus - E Q 3 ) {
$LicenseInf = " Additional grace period (KMS license expired or hardware out of tolerance) "
if ($null - N E $ _ x p r ) { $ E x p i r e M s g = " A d d i t i o n a l g r a c e p e r i o d e n d s $ _ x p r " }
}
if ($LicenseStatus - E Q 4 ) {
$LicenseInf = " Non-genuine grace period "
if ($null - N E $ _ x p r ) { $ E x p i r e M s g = " N o n - g e n u i n e g r a c e p e r i o d e n d s $ _ x p r " }
}
if ($LicenseStatus - E Q 5 - A n d - N o t $ N T 5 ) {
$LicenseInf = " Notification "
$LicenseMsg = " Notification Reason: $LicenseReason "
2025-01-30 02:25:04 +05:30
if ($LicenseReason - E Q " 0 x C 0 0 4 F 0 0 F " ) { i f ( $ n u l l - N E $ c K m s C l i e n t ) { $ L i c e n s e M s g = $ L i c e n s e M s g + " ( K M S l i c e n s e e x p i r e d ) . " } e l s e { $ L i c e n s e M s g = $ L i c e n s e M s g + " ( h a r d w a r e o u t o f t o l e r a n c e ) . " } }
2024-07-13 04:46:38 +05:30
if ($LicenseReason - E Q " 0 x C 0 0 4 F 2 0 0 " ) { $ L i c e n s e M s g = $ L i c e n s e M s g + " ( n o n - g e n u i n e ) . " }
2025-01-30 02:25:04 +05:30
if ($LicenseReason - E Q " 0 x C 0 0 4 F 0 0 9 " - O r $ L i c e n s e R e a s o n - E Q " 0 x C 0 0 4 F 0 6 4 " ) { $ L i c e n s e M s g = $ L i c e n s e M s g + " ( g r a c e t i m e e x p i r e d ) . " }
2024-07-13 04:46:38 +05:30
}
if ($LicenseStatus - G T 5 - O r ( $ L i c e n s e S t a t u s - G T 4 - A n d $ N T 5 ) ) {
$LicenseInf = " Unknown "
$LicenseMsg = $null
}
if ($LicenseStatus - E Q 6 - A n d - N o t $ V i s t a - A n d - N o t $ N T 5 ) {
$LicenseInf = " Extended grace period "
if ($null - N E $ _ x p r ) { $ E x p i r e M s g = " E x t e n d e d g r a c e p e r i o d e n d s $ _ x p r " }
}
if ($winPR - A n d $ P a r t i a l P r o d u c t K e y - A n d - N o t $ N T 9 ) {
2025-01-30 02:25:04 +05:30
$dp4 = strGetRegistry " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion " " DigitalProductId4 "
2024-07-13 04:46:38 +05:30
if ($null - N E $ d p 4 ) {
$ProductKeyChannel = ([System.Text.Encoding]::Unicode.GetString($dp4, 1016, 128)).Trim([char]$null)
}
}
2025-01-30 02:25:04 +05:30
if ($winPR - A n d $ D l v - A n d $ n u l l - E Q $ R e m a i n i n g A p p R e A r m C o u n t ) {
try
{
$tmp = [wmisearcher]" SELECT RemainingWindowsReArmCount FROM $strSLS "
$tmp.Options.Rewindable = $false
$tmp.Get() | select -Expand Properties -EA 0 | foreach {set $_.Name $_.Value}
$tmp.Dispose()
}
catch
{
}
}
$add_on = $Name.IndexOf(" add-on for " , 5)
& $isAll
if ($add_on - E Q - 1 ) { C O N O U T " N a m e : $ N a m e " } e l s e { C O N O U T " N a m e : $ ( $ N a m e . S u b s t r i n g ( 0 , $ a d d _ o n + 7 ) ) " }
CONOUT " Description: $Description "
CONOUT " Activation ID: $ID "
if ($null - N E $ P r o d u c t K e y I D ) { C O N O U T " E x t e n d e d P I D : $ P r o d u c t K e y I D " }
if ($null - N E $ P r o d u c t K e y I D 2 - A n d $ D l v ) { C O N O U T " P r o d u c t I D : $ P r o d u c t K e y I D 2 " }
if ($null - N E $ O f f l i n e I n s t a l l a t i o n I d - A n d $ I I D ) { C O N O U T " I n s t a l l a t i o n I D : $ O f f l i n e I n s t a l l a t i o n I d " }
if ($null - N E $ P r o d u c t K e y C h a n n e l ) { C O N O U T " P r o d u c t K e y C h a n n e l : $ P r o d u c t K e y C h a n n e l " }
if ($null - N E $ P a r t i a l P r o d u c t K e y ) { C O N O U T " P a r t i a l P r o d u c t K e y : $ P a r t i a l P r o d u c t K e y " }
CONOUT " License Status: $LicenseInf "
if ($null - N E $ L i c e n s e M s g ) { C O N O U T " $ L i c e n s e M s g " }
2024-07-13 04:46:38 +05:30
if ($LicenseStatus - N E 0 - A n d $ E v a l u a t i o n E n d D a t e . S u b s t r i n g ( 0 , 4 ) - N E " 1 6 0 1 " ) {
$EED = [DateTime]::Parse([Management.ManagementDateTimeConverter]::ToDateTime($EvaluationEndDate),$null,48).ToString('yyyy-MM-dd hh:mm:ss tt')
2025-01-30 02:25:04 +05:30
CONOUT " Evaluation End Date: $EED UTC "
}
if ($Dlv) {
if ($null - N E $ R e m a i n i n g W i n d o w s R e A r m C o u n t ) {
CONOUT " Remaining Windows rearm count: $RemainingWindowsReArmCount "
}
if ($null - N E $ R e m a i n i n g S k u R e A r m C o u n t - A n d $ R e m a i n i n g S k u R e A r m C o u n t - N E 4 2 9 4 9 6 7 2 9 5 ) {
CONOUT " Remaining $reapp rearm count: $RemainingAppReArmCount "
CONOUT " Remaining SKU rearm count: $RemainingSkuReArmCount "
}
if ($null - N E $ T r u s t e d T i m e - A n d $ L i c e n s e S t a t u s - N E 0 ) {
$TTD = [DateTime]::Parse([Management.ManagementDateTimeConverter]::ToDateTime($TrustedTime),$null,32).ToString('yyyy-MM-dd hh:mm:ss tt')
CONOUT " Trusted time: $TTD "
}
}
if ($LicenseStatus - E Q 0 ) {
return
}
if ($strSLP - E Q $ w s l p - A n d $ n u l l - N E $ P a r t i a l P r o d u c t K e y - A n d $ n u l l - N E $ A D A c t i v a t i o n O b j e c t N a m e - A n d $ V L A c t i v a t i o n T y p e - E Q 1 ) {
DetectAdbaClient
2024-07-13 04:46:38 +05:30
}
if ($winID - A n d $ n u l l - N E $ c A v m C l i e n t - A n d $ n u l l - N E $ P a r t i a l P r o d u c t K e y ) {
DetectAvmClient
}
$chkSub = ($winPR -And $cSub)
$chkSLS = ($null -NE $PartialProductKey) -And ($null -NE $cKmsClient -Or $null -NE $cKmsHost -Or $chkSub)
if (!$chkSLS) {
2025-01-30 02:25:04 +05:30
if ($null - N E $ E x p i r e M s g ) { C O N O U T " ` n $ E x p i r e M s g " }
2024-07-13 04:46:38 +05:30
return
}
2025-01-30 02:25:04 +05:30
try
{
$objSvc = New-Object PSObject
$wmiSvc = [wmisearcher]" SELECT * FROM $strSLS "
$wmiSvc.Options.Rewindable = $false
$wmiSvc.Get() | select -Expand Properties -EA 0 | foreach {
if (-Not [ S t r i n g ] : : I s N u l l O r E m p t y ( $ _ . V a l u e ) )
{
$objSvc | Add-Member 8 $_.Name $_.Value
if ($null - E Q $ I s K e y M a n a g e m e n t S e r v i c e M a c h i n e ) { s e t $ _ . N a m e $ _ . V a l u e }
}
2024-07-13 04:46:38 +05:30
}
2025-01-30 02:25:04 +05:30
$wmiSvc.Dispose()
}
catch
{
return
2024-07-13 04:46:38 +05:30
}
if ($strSLS - E Q $ w s l s - A n d $ N T 9 ) {
if ([String]::IsNullOrEmpty($DiscoveredKeyManagementServiceMachineIpAddress)) {
$DiscoveredKeyManagementServiceMachineIpAddress = " not available "
}
}
if ($null - N E $ c K m s H o s t - A n d $ I s K e y M a n a g e m e n t S e r v i c e M a c h i n e - G T 0 ) {
2025-01-30 02:25:04 +05:30
if ($null - N E $ E x p i r e M s g ) { C O N O U T " ` n $ E x p i r e M s g " }
2024-07-13 04:46:38 +05:30
DetectKmsHost
}
if ($null - N E $ c K m s C l i e n t ) {
DetectKmsClient
}
2025-01-30 02:25:04 +05:30
if ($null - E Q $ c K m s H o s t ) {
if ($null - N E $ E x p i r e M s g ) { C O N O U T " ` n $ E x p i r e M s g " }
}
2024-07-13 04:46:38 +05:30
if ($chkSub) {
DetectSubscription
}
}
#endregion
#region vNextDiag
if ($PSVersionTable.PSVersion.Major - L t 3 )
{
function ConvertFrom-Json
{
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline=$true)][Object]$item
)
[void][System.Reflection.Assembly]::LoadWithPartialName(" System.Web.Extensions " )
$psjs = New-Object System.Web.Script.Serialization.JavaScriptSerializer
Return ,$psjs.DeserializeObject($item)
}
function ConvertTo-Json
{
[CmdletBinding()]
Param(
[Parameter(ValueFromPipeline=$true)][Object]$item
)
[void][System.Reflection.Assembly]::LoadWithPartialName(" System.Web.Extensions " )
$psjs = New-Object System.Web.Script.Serialization.JavaScriptSerializer
Return $psjs.Serialize($item)
}
}
function PrintModePerPridFromRegistry
{
$vNextRegkey = " HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing\LicensingNext "
$vNextPrids = Get-Item -Path $vNextRegkey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty 'property' -ErrorAction SilentlyContinue | Where-Object -FilterScript {$_.ToLower() -like " *retail " -or $_.ToLower() -like " *volume " }
If ($null - E q $ v N e x t P r i d s )
{
2025-01-30 02:25:04 +05:30
CONOUT " `nNo registry keys found. "
2024-07-13 04:46:38 +05:30
Return
}
2025-01-30 02:25:04 +05:30
CONOUT " `r "
2024-07-13 04:46:38 +05:30
$vNextPrids | ForEach `
{
$mode = (Get-ItemProperty -Path $vNextRegkey -Name $_).$_
Switch ($mode)
{
2 { $mode = " vNext " ; Break }
3 { $mode = " Device " ; Break }
Default { $mode = " Legacy " ; Break }
}
2025-01-30 02:25:04 +05:30
CONOUT " $_ = $mode "
2024-07-13 04:46:38 +05:30
}
}
function PrintSharedComputerLicensing
{
$scaRegKey = " HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration "
$scaValue = Get-ItemProperty -Path $scaRegKey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty " SharedComputerLicensing " -ErrorAction SilentlyContinue
$scaRegKey2 = " HKLM:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing "
$scaValue2 = Get-ItemProperty -Path $scaRegKey2 -ErrorAction SilentlyContinue | Select-Object -ExpandProperty " SharedComputerLicensing " -ErrorAction SilentlyContinue
$scaPolicyKey = " HKLM:\SOFTWARE\Policies\Microsoft\Office\16.0\Common\Licensing "
$scaPolicyValue = Get-ItemProperty -Path $scaPolicyKey -ErrorAction SilentlyContinue | Select-Object -ExpandProperty " SharedComputerLicensing " -ErrorAction SilentlyContinue
If ($null - E q $ s c a V a l u e - A n d $ n u l l - E q $ s c a V a l u e 2 - A n d $ n u l l - E q $ s c a P o l i c y V a l u e )
{
2025-01-30 02:25:04 +05:30
CONOUT " `nNo registry keys found. "
2024-07-13 04:46:38 +05:30
Return
}
$scaModeValue = $scaValue -Or $scaValue2 -Or $scaPolicyValue
If ($scaModeValue - E q 0 )
{
$scaMode = " Disabled "
}
If ($scaModeValue - E q 1 )
{
$scaMode = " Enabled "
}
2025-01-30 02:25:04 +05:30
CONOUT " `nStatus: $scaMode "
CONOUT " `r "
2024-07-13 04:46:38 +05:30
$tokenFiles = $null
$tokenPath = " ${env:LOCALAPPDATA}\Microsoft\Office\16.0\Licensing "
If (Test-Path $ t o k e n P a t h )
{
$tokenFiles = Get-ChildItem -Path $tokenPath -Filter " *authString* " -Recurse | Where-Object { !$_.PSIsContainer }
}
If ($null - E q $ t o k e n F i l e s )
{
2025-01-30 02:25:04 +05:30
CONOUT " No tokens found. "
2024-07-13 04:46:38 +05:30
Return
}
If ($tokenFiles.Length - E q 0 )
{
2025-01-30 02:25:04 +05:30
CONOUT " No tokens found. "
2024-07-13 04:46:38 +05:30
Return
}
$tokenFiles | ForEach `
{
$tokenParts = (Get-Content -Encoding Unicode -Path $_.FullName).Split('_')
$output = New-Object PSObject
$output | Add-Member 8 'ACID' $tokenParts[0];
$output | Add-Member 8 'User' $tokenParts[3];
$output | Add-Member 8 'NotBefore' $tokenParts[4];
$output | Add-Member 8 'NotAfter' $tokenParts[5];
Write-Output $output
}
}
function PrintLicensesInformation
{
Param(
[ValidateSet(" NUL " , " Device " )]
[String]$mode
)
If ($mode - E q " N U L " )
{
$licensePath = " ${env:LOCALAPPDATA}\Microsoft\Office\Licenses "
}
ElseIf ($mode -Eq " Device " )
{
$licensePath = " ${env:PROGRAMDATA}\Microsoft\Office\Licenses "
}
$licenseFiles = $null
If (Test-Path $ l i c e n s e P a t h )
{
$licenseFiles = Get-ChildItem -Path $licensePath -Recurse | Where-Object { !$_.PSIsContainer }
}
2025-01-30 02:25:04 +05:30
If ($null - E q $ l i c e n s e F i l e s - O r $ l i c e n s e F i l e s . L e n g t h - E q 0 )
2024-07-13 04:46:38 +05:30
{
2025-01-30 02:25:04 +05:30
CONOUT " `nNo licenses found. "
2024-07-13 04:46:38 +05:30
Return
}
$licenseFiles | ForEach `
{
$license = (Get-Content -Encoding Unicode $_.FullName | ConvertFrom-Json).License
$decodedLicense = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($license)) | ConvertFrom-Json
$licenseType = $decodedLicense.LicenseType
If ($null - N e $ d e c o d e d L i c e n s e . E x p i r e s O n )
{
$expiry = [System.DateTime]::Parse($decodedLicense.ExpiresOn, $null, 'AdjustToUniversal')
}
Else
{
$expiry = New-Object System.DateTime
}
$licenseState = " Grace "
If ((Get-Date) - G t ( G e t - D a t e $ d e c o d e d L i c e n s e . M e t a d a t a . N o t A f t e r ) )
{
$licenseState = " RFM "
}
ElseIf ((Get-Date) -Lt (Get-Date $expiry))
{
$licenseState = " Licensed "
}
$output = New-Object PSObject
$output | Add-Member 8 'File' $_.PSChildName;
$output | Add-Member 8 'Version' $_.Directory.Name;
$output | Add-Member 8 'Type' " User|${licenseType} " ;
$output | Add-Member 8 'Product' $decodedLicense.ProductReleaseId;
$output | Add-Member 8 'Acid' $decodedLicense.Acid;
If ($mode - E q " D e v i c e " ) { $ o u t p u t | A d d - M e m b e r 8 ' D e v i c e I d ' $ d e c o d e d L i c e n s e . M e t a d a t a . D e v i c e I d ; }
$output | Add-Member 8 'LicenseState' $licenseState;
$output | Add-Member 8 'EntitlementStatus' $decodedLicense.Status;
$output | Add-Member 8 'EntitlementExpiration' (" N/A " , $decodedLicense.ExpiresOn)[!($null -eq $decodedLicense.ExpiresOn)];
$output | Add-Member 8 'ReasonCode' (" N/A " , $decodedLicense.ReasonCode)[!($null -eq $decodedLicense.ReasonCode)];
$output | Add-Member 8 'NotBefore' $decodedLicense.Metadata.NotBefore;
$output | Add-Member 8 'NotAfter' $decodedLicense.Metadata.NotAfter;
$output | Add-Member 8 'NextRenewal' $decodedLicense.Metadata.RenewAfter;
$output | Add-Member 8 'TenantId' (" N/A " , $decodedLicense.Metadata.TenantId)[!($null -eq $decodedLicense.Metadata.TenantId)];
#$output.PSObject.Properties | foreach { $ht = @{} } { $ht[$_.Name] = $_.Value } { $output = $ht | ConvertTo-Json }
Write-Output $output
}
}
function vNextDiagRun
{
$fNUL = ([IO.Directory]::Exists(" ${env:LOCALAPPDATA}\Microsoft\Office\Licenses " )) -and ([IO.Directory]::GetFiles(" ${env:LOCALAPPDATA}\Microsoft\Office\Licenses " , " * " , 1).Length -GE 0)
$fDev = ([IO.Directory]::Exists(" ${env:PROGRAMDATA}\Microsoft\Office\Licenses " )) -and ([IO.Directory]::GetFiles(" ${env:PROGRAMDATA}\Microsoft\Office\Licenses " , " * " , 1).Length -GE 0)
$rPID = $null -NE (GP " HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing\LicensingNext " -EA 0 | select -Expand 'property' -EA 0 | where -Filter {$_.ToLower() -like " *retail " -or $_.ToLower() -like " *volume " })
$rSCA = $null -NE (GP " HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration " -EA 0 | select -Expand " SharedComputerLicensing " -EA 0)
$rSCL = $null -NE (GP " HKLM:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing " -EA 0 | select -Expand " SharedComputerLicensing " -EA 0)
if (($fNUL - O r $ f D e v - O r $ r P I D - O r $ r S C A - O r $ r S C L ) - E Q $ f a l s e ) {
Return
}
2025-01-30 02:25:04 +05:30
& $isAll
CONOUT " $line2 "
CONOUT " === Office vNext Status === "
CONOUT " $line2 "
CONOUT " `n========== Mode per ProductReleaseId ========== "
2024-07-13 04:46:38 +05:30
PrintModePerPridFromRegistry
2025-01-30 02:25:04 +05:30
CONOUT " `n========== Shared Computer Licensing ========== "
2024-07-13 04:46:38 +05:30
PrintSharedComputerLicensing
2025-01-30 02:25:04 +05:30
CONOUT " `n========== vNext licenses =========== "
2024-07-13 04:46:38 +05:30
PrintLicensesInformation -Mode " NUL "
2025-01-30 02:25:04 +05:30
CONOUT " `n========== Device licenses ========== "
2024-07-13 04:46:38 +05:30
PrintLicensesInformation -Mode " Device "
2025-01-30 02:25:04 +05:30
CONOUT " $line3 "
CONOUT " `r "
2024-07-13 04:46:38 +05:30
}
#endregion
#region clic
< #
;;; Source: https://github.com/asdcorp/clic
;;; Powershell port: abbodi1406
Copyright 2023 asdcorp
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the " Software " ), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED " AS IS " , WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#>
function BoolToWStr($bVal) {
( " TRUE " , " FALSE " ) [!$bVal]
}
function InitializePInvoke {
$Marshal = [System.Runtime.InteropServices.Marshal]
$Module = [AppDomain]::CurrentDomain.DefineDynamicAssembly((Get-Random), 'Run').DefineDynamicModule((Get-Random))
$Class = $Module.DefineType('NativeMethods', 'Public, Abstract, Sealed, BeforeFieldInit', [Object], 0)
$Class.DefinePInvokeMethod('SLIsWindowsGenuineLocal', 'slc.dll', 'Public, Static', 'Standard', [Int32], @([UInt32].MakeByRefType()), 'Winapi', 'Unicode').SetImplementationFlags('PreserveSig')
$Class.DefinePInvokeMethod('SLGetWindowsInformationDWORD', 'slc.dll', 22, 1, [Int32], @([String], [UInt32].MakeByRefType()), 1, 3).SetImplementationFlags(128)
$Class.DefinePInvokeMethod('SLGetWindowsInformation', 'slc.dll', 22, 1, [Int32], @([String], [UInt32].MakeByRefType(), [UInt32].MakeByRefType(), [IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
if ($DllSubscription) {
$Class.DefinePInvokeMethod('ClipGetSubscriptionStatus', 'Clipc.dll', 22, 1, [Int32], @([IntPtr].MakeByRefType()), 1, 3).SetImplementationFlags(128)
$Struct = $Class.DefineNestedType('SubStatus', 'NestedPublic, SequentialLayout, Sealed, BeforeFieldInit', [ValueType], 0)
[void]$Struct.DefineField('dwEnabled', [UInt32], 'Public')
[void]$Struct.DefineField('dwSku', [UInt32], 6)
[void]$Struct.DefineField('dwState', [UInt32], 6)
$SubStatus = $Struct.CreateType()
}
$Win32 = $Class.CreateType()
}
function InitializeDigitalLicenseCheck {
$CAB = [System.Reflection.Emit.CustomAttributeBuilder]
$ICom = $Module.DefineType('EUM.IEUM', 'Public, Interface, Abstract, Import')
$ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.ComImportAttribute].GetConstructor(@()), @()))
$ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.GuidAttribute].GetConstructor(@([String])), @('F2DCB80D-0670-44BC-9002-CD18688730AF')))
$ICom.SetCustomAttribute($CAB::new([System.Runtime.InteropServices.InterfaceTypeAttribute].GetConstructor(@([Int16])), @([Int16]1)))
1..4 | % { [void]$ICom.DefineMethod('VF'+$_, 'Public, Virtual, HideBySig, NewSlot, Abstract', 'Standard, HasThis', [Void], @()) }
[void]$ICom.DefineMethod('AcquireModernLicenseForWindows', 1478, 33, [Int32], @([Int32], [Int32].MakeByRefType()))
$IEUM = $ICom.CreateType()
}
function PrintStateData {
$pwszStateData = 0
$cbSize = 0
if ($Win32::SLGetWindowsInformation(
" Security-SPP-Action-StateData " ,
[ref]$null,
[ref]$cbSize,
[ref]$pwszStateData
)) {
return $FALSE
}
[string[]]$pwszStateString = $Marshal::PtrToStringUni($pwszStateData) -replace " ; " , " `n "
2025-01-30 02:25:04 +05:30
CONOUT (" $pwszStateString " )
2024-07-13 04:46:38 +05:30
$Marshal::FreeHGlobal($pwszStateData)
return $TRUE
}
2025-01-30 02:25:04 +05:30
function PrintLastActivationHResult {
2024-07-13 04:46:38 +05:30
$pdwLastHResult = 0
$cbSize = 0
if ($Win32::SLGetWindowsInformation(
" Security-SPP-LastWindowsActivationHResult " ,
[ref]$null,
[ref]$cbSize,
[ref]$pdwLastHResult
)) {
return $FALSE
}
2025-01-30 02:25:04 +05:30
CONOUT (" LastActivationHResult=0x{0:x8} " -f $Marshal::ReadInt32($pdwLastHResult))
2024-07-13 04:46:38 +05:30
$Marshal::FreeHGlobal($pdwLastHResult)
return $TRUE
}
2025-01-30 02:25:04 +05:30
function PrintLastActivationTime {
$pdwLastTime = 0
$cbSize = 0
if ($Win32::SLGetWindowsInformation(
" Security-SPP-LastWindowsActivationTime " ,
[ref]$null,
[ref]$cbSize,
[ref]$pdwLastTime
)) {
return $FALSE
}
$actTime = $Marshal::ReadInt64($pdwLastTime)
if ($actTime - n e 0 ) {
CONOUT (" LastActivationTime={0} " -f [DateTime]::FromFileTimeUtc($actTime).ToString(" yyyy/MM/dd:HH:mm:ss " ))
}
$Marshal::FreeHGlobal($pdwLastTime)
return $TRUE
}
2024-07-13 04:46:38 +05:30
function PrintIsWindowsGenuine {
$dwGenuine = 0
$ppwszGenuineStates = @(
" SL_GEN_STATE_IS_GENUINE " ,
" SL_GEN_STATE_INVALID_LICENSE " ,
" SL_GEN_STATE_TAMPERED " ,
" SL_GEN_STATE_OFFLINE " ,
" SL_GEN_STATE_LAST "
)
if ($Win32::SLIsWindowsGenuineLocal([ref]$dwGenuine)) {
return $FALSE
}
if ($dwGenuine - l t 5 ) {
2025-01-30 02:25:04 +05:30
CONOUT (" IsWindowsGenuine={0} " -f $ppwszGenuineStates[$dwGenuine])
2024-07-13 04:46:38 +05:30
} else {
2025-01-30 02:25:04 +05:30
CONOUT (" IsWindowsGenuine={0} " -f $dwGenuine)
2024-07-13 04:46:38 +05:30
}
return $TRUE
}
function PrintDigitalLicenseStatus {
try {
. InitializeDigitalLicenseCheck
$ComObj = New-Object -Com EditionUpgradeManagerObj.EditionUpgradeManager
} catch {
return $FALSE
}
$parameters = 1, $null
if ([EUM.IEUM].GetMethod(" AcquireModernLicenseForWindows " ).Invoke($ComObj, $ p a r a m e t e r s ) ) {
return $FALSE
}
$dwReturnCode = $parameters[1]
[bool]$bDigitalLicense = $FALSE
$bDigitalLicense = (($dwReturnCode -ge 0) -and ($dwReturnCode -ne 1))
2025-01-30 02:25:04 +05:30
CONOUT (" IsDigitalLicense={0} " -f (BoolToWStr $bDigitalLicense))
2024-07-13 04:46:38 +05:30
return $TRUE
}
function PrintSubscriptionStatus {
$dwSupported = 0
if ($winbuild - g e 1 5 0 6 3 ) {
$pwszPolicy = " ConsumeAddonPolicySet "
} else {
$pwszPolicy = " Allow-WindowsSubscription "
}
if ($Win32::SLGetWindowsInformationDWORD($pwszPolicy, [ r e f ] $ d w S u p p o r t e d ) ) {
return $FALSE
}
2025-01-30 02:25:04 +05:30
CONOUT (" SubscriptionSupportedEdition={0} " -f (BoolToWStr $dwSupported))
2024-07-13 04:46:38 +05:30
$pStatus = $Marshal::AllocHGlobal($Marshal::SizeOf([Type]$SubStatus))
if ($Win32::ClipGetSubscriptionStatus([ref]$pStatus)) {
return $FALSE
}
$sStatus = [Activator]::CreateInstance($SubStatus)
$sStatus = $Marshal::PtrToStructure($pStatus, [Type]$SubStatus)
$Marshal::FreeHGlobal($pStatus)
2025-01-30 02:25:04 +05:30
CONOUT (" SubscriptionEnabled={0} " -f (BoolToWStr $sStatus.dwEnabled))
2024-07-13 04:46:38 +05:30
if ($sStatus.dwEnabled - e q 0 ) {
return $TRUE
}
2025-01-30 02:25:04 +05:30
CONOUT (" SubscriptionSku={0} " -f $sStatus.dwSku)
CONOUT (" SubscriptionState={0} " -f $sStatus.dwState)
2024-07-13 04:46:38 +05:30
return $TRUE
}
function ClicRun
{
2025-01-30 02:25:04 +05:30
& $isAll
CONOUT " Client Licensing Check information: "
2024-07-13 04:46:38 +05:30
$null = PrintStateData
2025-01-30 02:25:04 +05:30
$null = PrintLastActivationHResult
$null = PrintLastActivationTime
2024-07-13 04:46:38 +05:30
$null = PrintIsWindowsGenuine
if ($DllDigital) {
$null = PrintDigitalLicenseStatus
}
if ($DllSubscription) {
$null = PrintSubscriptionStatus
}
2025-01-30 02:25:04 +05:30
CONOUT " $line3 "
& $noAll
2024-07-13 04:46:38 +05:30
}
#endregion
$Host.UI.RawUI.WindowTitle = " Check Activation Status "
2025-01-30 02:25:04 +05:30
UnQuickEdit
2024-07-13 04:46:38 +05:30
if ($All.IsPresent) {
2025-01-30 02:25:04 +05:30
$B=$Host.UI.RawUI.BufferSize;$B.Height=3000;$Host.UI.RawUI.BufferSize=$B;
if (!$Pass.IsPresent) { c l e a r ; }
2024-07-13 04:46:38 +05:30
}
$wslp = " SoftwareLicensingProduct "
$wsls = " SoftwareLicensingService "
$oslp = " OfficeSoftwareProtectionProduct "
$osls = " OfficeSoftwareProtectionService "
$winApp = " 55c92734-d682-4d71-983e-d6ec3f16059f "
$o14App = " 59a52881-a989-479d-af46-f275c6370663 "
$o15App = " 0ff1ce15-a989-479d-af46-f275c6370663 "
$cSub = ($winbuild -GE 19041) -And (Select-String -Path " $SysPath\wbem\sppwmi.mof " -Encoding unicode -Pattern " SubscriptionType " )
$DllDigital = ($winbuild -GE 14393) -And (Test-Path " $SysPath\EditionUpgradeManagerObj.dll " )
$DllSubscription = ($winbuild -GE 14393) -And (Test-Path " $SysPath\Clipc.dll " )
$VLActTypes = @(" All " , " AD " , " KMS " , " Token " )
2025-01-30 02:25:04 +05:30
$SLKeyPath = " HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SL "
$NSKeyPath = " HKEY_USERS\S-1-5-20\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SL "
2024-07-13 04:46:38 +05:30
2025-01-30 02:25:04 +05:30
'cW1nd0ws', 'c0ff1ce15', 'c0ff1ce14', 'ospp14', 'ospp15' | foreach {set $_ $false}
2024-07-13 04:46:38 +05:30
2025-01-30 02:25:04 +05:30
$offsvc = " osppsvc "
if ($NT7 - O r - N o t $ N T 6 ) { $ w i n s v c = " s p p s v c " } e l s e { $ w i n s v c = " s l s v c " }
2024-07-13 04:46:38 +05:30
2025-01-30 02:25:04 +05:30
try {gsv $winsvc -EA 1 | Out-Null; $WsppHook = 1} catch {$WsppHook = 0}
try {gsv $offsvc -EA 1 | Out-Null; $OsppHook = 1} catch {$OsppHook = 0}
2024-07-13 04:46:38 +05:30
2025-01-30 02:25:04 +05:30
if ($WsppHook - N E 0 ) {
try {sasv $winsvc -EA 1} catch {}
$cW1nd0ws = DetectID $wslp $winApp
$c0ff1ce15 = DetectID $wslp $o15App
$c0ff1ce14 = DetectID $wslp $o14App
}
2024-07-13 04:46:38 +05:30
if ($OsppHook - N E 0 ) {
2025-01-30 02:25:04 +05:30
try {sasv $offsvc -EA 1} catch {}
$ospp15 = DetectID $oslp $o15App
$ospp14 = DetectID $oslp $o14App
2024-07-13 04:46:38 +05:30
}
2025-01-30 02:25:04 +05:30
if ($cW1nd0ws)
2024-07-13 04:46:38 +05:30
{
echoWindows
GetID $wslp $winApp | foreach -EA 1 {
GetResult $wslp $wsls $_
2025-01-30 02:25:04 +05:30
CONOUT " $line3 "
& $noAll
2024-07-13 04:46:38 +05:30
}
}
elseif ($NT6)
{
echoWindows
2025-01-30 02:25:04 +05:30
CONOUT " `nError: product key not found. "
2024-07-13 04:46:38 +05:30
}
if ($winbuild - G E 9 2 0 0 ) {
. InitializePInvoke
ClicRun
}
if ($c0ff1ce15 - O r $ o s p p 1 5 ) {
CheckOhook
}
$doMSG = 1
2025-01-30 02:25:04 +05:30
if ($c0ff1ce15)
{
2024-07-13 04:46:38 +05:30
echoOffice
GetID $wslp $o15App | foreach -EA 1 {
GetResult $wslp $wsls $_
2025-01-30 02:25:04 +05:30
CONOUT " $line3 "
& $noAll
2024-07-13 04:46:38 +05:30
}
}
2025-01-30 02:25:04 +05:30
if ($c0ff1ce14)
{
2024-07-13 04:46:38 +05:30
echoOffice
GetID $wslp $o14App | foreach -EA 1 {
GetResult $wslp $wsls $_
2025-01-30 02:25:04 +05:30
CONOUT " $line3 "
& $noAll
2024-07-13 04:46:38 +05:30
}
}
2025-01-30 02:25:04 +05:30
if ($ospp15)
{
2024-07-13 04:46:38 +05:30
echoOffice
GetID $oslp $o15App | foreach -EA 1 {
GetResult $oslp $osls $_
2025-01-30 02:25:04 +05:30
CONOUT " $line3 "
& $noAll
2024-07-13 04:46:38 +05:30
}
}
2025-01-30 02:25:04 +05:30
if ($ospp14)
{
2024-07-13 04:46:38 +05:30
echoOffice
GetID $oslp $o14App | foreach -EA 1 {
GetResult $oslp $osls $_
2025-01-30 02:25:04 +05:30
CONOUT " $line3 "
& $noAll
2024-07-13 04:46:38 +05:30
}
}
if ($NT7) {
vNextDiagRun
}
ExitScript 0
: sppmgr :