From bdb9875a6baf64321fb6789faf13f648c2a7854a Mon Sep 17 00:00:00 2001 From: WindowsAddict Date: Sat, 13 Jul 2024 04:46:38 +0530 Subject: [PATCH] Remove check activation status scripts and replace them with @abbodi1406's CAS https://gravesoft.dev/cas --- .../Check-Activation-Status-vbs.cmd | 259 ----- .../Check-Activation-Status-wmi.cmd | 564 --------- .../Check-Activation-Status.cmd | 1025 +++++++++++++++++ 3 files changed, 1025 insertions(+), 823 deletions(-) delete mode 100644 MAS/Separate-Files-Version/Check-Activation-Status-vbs.cmd delete mode 100644 MAS/Separate-Files-Version/Check-Activation-Status-wmi.cmd create mode 100644 MAS/Separate-Files-Version/Check-Activation-Status.cmd diff --git a/MAS/Separate-Files-Version/Check-Activation-Status-vbs.cmd b/MAS/Separate-Files-Version/Check-Activation-Status-vbs.cmd deleted file mode 100644 index c0d7507..0000000 --- a/MAS/Separate-Files-Version/Check-Activation-Status-vbs.cmd +++ /dev/null @@ -1,259 +0,0 @@ -@setlocal DisableDelayedExpansion -@echo off -@cls - - -:: -:: Check-Activation-Status -:: Written by @abbodi1406 -:: forums.mydigitallife.net/posts/838808 - - - -set _args= -set _args=%* -for %%A in (%_args%) do ( -if /i "%%A"=="-wow" set _rel1=1 -if /i "%%A"=="-arm" set _rel2=1 -) -set "_cmdf=%~f0" -if exist "%SystemRoot%\Sysnative\cmd.exe" if not defined _rel1 ( -setlocal EnableDelayedExpansion -start %SystemRoot%\Sysnative\cmd.exe /c ""!_cmdf!" -wow" -exit /b -) -if exist "%SystemRoot%\SysArm32\cmd.exe" if /i %PROCESSOR_ARCHITECTURE%==AMD64 if not defined _rel2 ( -setlocal EnableDelayedExpansion -start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" -arm" -exit /b -) -color 07 -title Check Activation Status [vbs] -set "SysPath=%SystemRoot%\System32" -set "Path=%SystemRoot%\System32;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\" -if exist "%SystemRoot%\Sysnative\reg.exe" ( -set "SysPath=%SystemRoot%\Sysnative" -set "Path=%SystemRoot%\Sysnative;%SystemRoot%\Sysnative\Wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%Path%" -) - -:: Check LF line ending - -pushd "%~dp0" ->nul findstr /v "$" "%~nx0" && ( -echo: -echo Error: Script either has LF line ending issue or an empty line at the end of the script is missing. -echo: -ping 127.0.0.1 -n 6 >nul -popd -exit /b -) -popd - -set ohook= -for %%# in (15 16) do ( -for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do ( -if exist "%%~A\Microsoft Office\Office%%#\sppc*dll" set ohook=1 -) -) - -for %%# in (System SystemX86) do ( -for %%G in ("Office 15" "Office") do ( -for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do ( -if exist "%%~A\Microsoft %%~G\root\vfs\%%#\sppc*dll" set ohook=1 -) -) -) - -set "_bit=64" -set "_wow=1" -if /i "%PROCESSOR_ARCHITECTURE%"=="x86" if "%PROCESSOR_ARCHITEW6432%"=="" set "_wow=0"&set "_bit=32" -set "_utemp=%TEMP%" -set "line2=************************************************************" -set "line3=____________________________________________________________" -set _sO16vbs=0 -set _sO15vbs=0 -if exist "%ProgramFiles%\Microsoft Office\Office15\ospp.vbs" ( - set _sO15vbs=1 -) else if exist "%ProgramW6432%\Microsoft Office\Office15\ospp.vbs" ( - set _sO15vbs=1 -) else if exist "%ProgramFiles(x86)%\Microsoft Office\Office15\ospp.vbs" ( - set _sO15vbs=1 -) -setlocal EnableDelayedExpansion -echo %line2% -echo *** Windows Status *** -echo %line2% -pushd "!_utemp!" -copy /y %SystemRoot%\System32\slmgr.vbs . >nul 2>&1 -net start sppsvc /y >nul 2>&1 -cscript //nologo slmgr.vbs /dli || (echo Error executing slmgr.vbs&del /f /q slmgr.vbs&popd&goto :casVend) -cscript //nologo slmgr.vbs /xpr -del /f /q slmgr.vbs >nul 2>&1 -popd -echo %line3% - -if defined ohook ( -echo. -echo. -echo %line2% -echo *** Office Ohook Activation Status *** -echo %line2% -echo. -powershell "write-host -back 'Black' -fore 'Yellow' 'Ohook for permanent Office activation is installed.'; write-host -back 'Black' -fore 'Yellow' 'You can ignore below Office activation status.'" -echo. -) - -:casVo16 -set office= -for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\16.0\Common\InstallRoot /v Path" 2^>nul') do (set "office=%%b") -if exist "!office!\ospp.vbs" ( -set _sO16vbs=1 -echo. -echo %line2% -if %_sO15vbs% EQU 0 ( -echo *** Office 2016 %_bit%-bit Status *** -) else ( -echo *** Office 2013/2016 Status *** -) -echo %line2% -cscript //nologo "!office!\ospp.vbs" /dstatus -) -if %_wow%==0 goto :casVo13 -set office= -for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\16.0\Common\InstallRoot /v Path" 2^>nul') do (set "office=%%b") -if exist "!office!\ospp.vbs" ( -set _sO16vbs=1 -echo. -echo %line2% -if %_sO15vbs% EQU 0 ( -echo *** Office 2016 32-bit Status *** -) else ( -echo *** Office 2013/2016 Status *** -) -echo %line2% -cscript //nologo "!office!\ospp.vbs" /dstatus -) - -:casVo13 -if %_sO16vbs% EQU 1 goto :casVo10 -set office= -for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\15.0\Common\InstallRoot /v Path" 2^>nul') do (set "office=%%b") -if exist "!office!\ospp.vbs" ( -echo. -echo %line2% -echo *** Office 2013 %_bit%-bit Status *** -echo %line2% -cscript //nologo "!office!\ospp.vbs" /dstatus -) -if %_wow%==0 goto :casVo10 -set office= -for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\15.0\Common\InstallRoot /v Path" 2^>nul') do (set "office=%%b") -if exist "!office!\ospp.vbs" ( -echo. -echo %line2% -echo *** Office 2013 32-bit Status *** -echo %line2% -cscript //nologo "!office!\ospp.vbs" /dstatus -) - -:casVo10 -set office= -for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\14.0\Common\InstallRoot /v Path" 2^>nul') do (set "office=%%b") -if exist "!office!\ospp.vbs" ( -echo. -echo %line2% -echo *** Office 2010 %_bit%-bit Status *** -echo %line2% -cscript //nologo "!office!\ospp.vbs" /dstatus -) -if %_wow%==0 goto :casVc16 -set office= -for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\Common\InstallRoot /v Path" 2^>nul') do (set "office=%%b") -if exist "!office!\ospp.vbs" ( -echo. -echo %line2% -echo *** Office 2010 32-bit Status *** -echo %line2% -cscript //nologo "!office!\ospp.vbs" /dstatus -) - -:casVc16 -reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun /v InstallPath >nul 2>&1 || ( -reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun /v InstallPath >nul 2>&1 || goto :casVc13 -) -set office= -for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\Microsoft\Office\ClickToRun /v InstallPath" 2^>nul') do (set "office=%%b\Office16") -if exist "!office!\ospp.vbs" ( -set _sO16vbs=1 -echo. -echo %line2% -if %_sO15vbs% EQU 0 ( -echo *** Office 2016-2021 C2R Status *** -) else ( -echo *** Office 2013-2021 Status *** -) -echo %line2% -cscript //nologo "!office!\ospp.vbs" /dstatus -) -if %_wow%==0 goto :casVc13 -set office= -for /f "skip=2 tokens=2*" %%a in ('"reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun /v InstallPath" 2^>nul') do (set "office=%%b\Office16") -if exist "!office!\ospp.vbs" ( -set _sO16vbs=1 -echo. -echo %line2% -if %_sO15vbs% EQU 0 ( -echo *** Office 2016-2021 C2R Status *** -) else ( -echo *** Office 2013-2021 Status *** -) -echo %line2% -cscript //nologo "!office!\ospp.vbs" /dstatus -) - -:casVc13 -if %_sO16vbs% EQU 1 goto :casVc10 -reg query HKLM\SOFTWARE\Microsoft\Office\15.0\ClickToRun /v InstallPath >nul 2>&1 || ( -reg query HKLM\SOFTWARE\WOW6432Node\Microsoft\Office\15.0\ClickToRun /v InstallPath >nul 2>&1 || goto :casVc10 -) -set office= -if exist "%ProgramFiles%\Microsoft Office\Office15\ospp.vbs" ( - set "office=%ProgramFiles%\Microsoft Office\Office15" -) else if exist "%ProgramW6432%\Microsoft Office\Office15\ospp.vbs" ( - set "office=%ProgramW6432%\Microsoft Office\Office15" -) else if exist "%ProgramFiles(x86)%\Microsoft Office\Office15\ospp.vbs" ( - set "office=%ProgramFiles(x86)%\Microsoft Office\Office15" -) -if exist "!office!\ospp.vbs" ( -echo. -echo %line2% -echo *** Office 2013 C2R Status *** -echo %line2% -cscript //nologo "!office!\ospp.vbs" /dstatus -) - -:casVc10 -if %_wow%==0 reg query HKLM\SOFTWARE\Microsoft\Office\14.0\CVH /f Click2run /k >nul 2>&1 || goto :casVend -if %_wow%==1 reg query HKLM\SOFTWARE\Wow6432Node\Microsoft\Office\14.0\CVH /f Click2run /k >nul 2>&1 || goto :casVend -set office= -if exist "%ProgramFiles%\Microsoft Office\Office14\ospp.vbs" ( - set "office=%ProgramFiles%\Microsoft Office\Office14" -) else if exist "%ProgramW6432%\Microsoft Office\Office14\ospp.vbs" ( - set "office=%ProgramW6432%\Microsoft Office\Office14" -) else if exist "%ProgramFiles(x86)%\Microsoft Office\Office14\ospp.vbs" ( - set "office=%ProgramFiles(x86)%\Microsoft Office\Office14" -) -if exist "!office!\ospp.vbs" ( -echo. -echo %line2% -echo *** Office 2010 C2R Status *** -echo %line2% -cscript //nologo "!office!\ospp.vbs" /dstatus -) - -:casVend -echo. -echo Press any key to exit. -pause >nul -exit /b -:: Leave empty line below diff --git a/MAS/Separate-Files-Version/Check-Activation-Status-wmi.cmd b/MAS/Separate-Files-Version/Check-Activation-Status-wmi.cmd deleted file mode 100644 index ce735bb..0000000 --- a/MAS/Separate-Files-Version/Check-Activation-Status-wmi.cmd +++ /dev/null @@ -1,564 +0,0 @@ -@setlocal DisableDelayedExpansion -@echo off - - - -:: Check-Activation-Status -:: Written by @abbodi1406 -:: forums.mydigitallife.net/posts/838808 - - - - -set WMI_VBS=0 -@cls -set _args= -set _args=%* -for %%A in (%_args%) do ( -if /i "%%A"=="-wow" set _rel1=1 -if /i "%%A"=="-arm" set _rel2=1 -) -set "_cmdf=%~f0" -if exist "%SystemRoot%\Sysnative\cmd.exe" if not defined _rel1 ( -setlocal EnableDelayedExpansion -start %SystemRoot%\Sysnative\cmd.exe /c ""!_cmdf!" -wow" -exit /b -) -if exist "%SystemRoot%\SysArm32\cmd.exe" if /i %PROCESSOR_ARCHITECTURE%==AMD64 if not defined _rel2 ( -setlocal EnableDelayedExpansion -start %SystemRoot%\SysArm32\cmd.exe /c ""!_cmdf!" -arm" -exit /b -) -color 07 -title Check Activation Status [wmi] -set wspp=SoftwareLicensingProduct -set wsps=SoftwareLicensingService -set ospp=OfficeSoftwareProtectionProduct -set osps=OfficeSoftwareProtectionService -set winApp=55c92734-d682-4d71-983e-d6ec3f16059f -set o14App=59a52881-a989-479d-af46-f275c6370663 -set o15App=0ff1ce15-a989-479d-af46-f275c6370663 -for %%# in (spp_get,ospp_get,cW1nd0ws,sppw,c0ff1ce15,sppo,osppsvc,ospp14,ospp15) do set "%%#=" -for /f "tokens=6 delims=[]. " %%# in ('ver') do set winbuild=%%# -set "spp_get=Description, DiscoveredKeyManagementServiceMachineName, DiscoveredKeyManagementServiceMachinePort, EvaluationEndDate, GracePeriodRemaining, ID, KeyManagementServiceMachine, KeyManagementServicePort, KeyManagementServiceProductKeyID, LicenseStatus, LicenseStatusReason, Name, PartialProductKey, ProductKeyID, VLActivationInterval, VLRenewalInterval" -set "ospp_get=%spp_get%" -if %winbuild% GEQ 9200 set "spp_get=%spp_get%, KeyManagementServiceLookupDomain, VLActivationTypeEnabled" -if %winbuild% GEQ 9600 set "spp_get=%spp_get%, DiscoveredKeyManagementServiceMachineIpAddress, ProductKeyChannel" -set "_work=%~dp0" -set "_batf=%~f0" -set "_batp=%_batf:'=''%" -set "_Local=%LocalAppData%" -set _Identity=0 -setlocal EnableDelayedExpansion -dir /b /s /a:-d "!_Local!\Microsoft\Office\Licenses\*1*" 1>nul 2>nul && set _Identity=1 -dir /b /s /a:-d "!ProgramData!\Microsoft\Office\Licenses\*1*" 1>nul 2>nul && set _Identity=1 -pushd "!_work!" -setlocal DisableDelayedExpansion -if %winbuild% LSS 9200 if not exist "%SystemRoot%\servicing\Packages\Microsoft-Windows-PowerShell-WTR-Package~*.mum" set _Identity=0 - -set "SysPath=%SystemRoot%\System32" -set "Path=%SystemRoot%\System32;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\" -if exist "%SystemRoot%\Sysnative\reg.exe" ( -set "SysPath=%SystemRoot%\Sysnative" -set "Path=%SystemRoot%\Sysnative;%SystemRoot%\Sysnative\Wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%Path%" -) - -:: Check LF line ending - -pushd "%~dp0" ->nul findstr /v "$" "%~nx0" && ( -echo: -echo Error: Script either has LF line ending issue or an empty line at the end of the script is missing. -echo: -ping 127.0.0.1 -n 6 >nul -popd -exit /b -) -popd - -set ohook= -for %%# in (15 16) do ( -for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do ( -if exist "%%~A\Microsoft Office\Office%%#\sppc*dll" set ohook=1 -) -) - -for %%# in (System SystemX86) do ( -for %%G in ("Office 15" "Office") do ( -for %%A in ("%ProgramFiles%" "%ProgramW6432%" "%ProgramFiles(x86)%") do ( -if exist "%%~A\Microsoft %%~G\root\vfs\%%#\sppc*dll" set ohook=1 -) -) -) - -set _cwmi=0 -for %%# in (wmic.exe) do @if not "%%~$PATH:#"=="" ( -wmic path Win32_ComputerSystem get CreationClassName /value 2>nul | find /i "ComputerSystem" 1>nul && set _cwmi=1 -) - -if %_cwmi% EQU 0 ( -echo: -echo Error: WMI is not responding in the system. -echo: -echo In MAS, Goto Troubleshoot and run Fix WMI option. -echo: -echo Press any key to exit... -pause >nul -exit /b -) - -set "line2=************************************************************" -set "line3=____________________________________________________________" -set "_psc=powershell" - -set _prsh=1 -for %%# in (powershell.exe) do @if "%%~$PATH:#"=="" set _prsh=0 -set "_csg=cscript.exe //NoLogo //Job:WmiMulti "%~nx0?.wsf"" -set "_csq=cscript.exe //NoLogo //Job:WmiQuery "%~nx0?.wsf"" -set "_csx=cscript.exe //NoLogo //Job:XPDT "%~nx0?.wsf"" -if %_cwmi% EQU 0 set WMI_VBS=1 -if %WMI_VBS% EQU 0 ( -set "_zz1=wmic path" -set "_zz2=where" -set "_zz3=get" -set "_zz4=/value" -set "_zz5=(" -set "_zz6=)" -set "_zz7="wmic path" -set "_zz8=/value"" -) else ( -set "_zz1=%_csq%" -set "_zz2=" -set "_zz3=" -set "_zz4=" -set "_zz5="" -set "_zz6="" -set "_zz7=%_csq%" -set "_zz8=" -) -set _WSH=0 -set OsppHook=1 -sc query osppsvc >nul 2>&1 -if %errorlevel% EQU 1060 set OsppHook=0 - -net start sppsvc /y >nul 2>&1 -call :casWpkey %wspp% %winApp% cW1nd0ws sppw -if %winbuild% GEQ 9200 call :casWpkey %wspp% %o15App% c0ff1ce15 sppo -if %OsppHook% NEQ 0 ( -net start osppsvc /y >nul 2>&1 -call :casWpkey %ospp% %o14App% osppsvc ospp14 -if %winbuild% LSS 9200 call :casWpkey %ospp% %o15App% osppsvc ospp15 -) - -echo %line2% -echo *** Windows Status *** -echo %line2% -if not defined cW1nd0ws ( -echo. -echo Error: product key not found. -goto :casWcon -) -set winID=1 -set "_qr=%_zz7% %wspp% %_zz2% %_zz5%ApplicationID='%winApp%' and PartialProductKey is not null%_zz6% %_zz3% ID %_zz8%" -for /f "tokens=2 delims==" %%# in ('%_qr%') do ( - set "chkID=%%#" - call :casWdet "%wspp%" "%wsps%" "%spp_get%" - call :casWout - echo %line3% - echo. -) - -if defined ohook ( -echo. -echo. -echo %line2% -echo *** Office Ohook Activation Status *** -echo %line2% -echo. -powershell "write-host -back 'Black' -fore 'Yellow' 'Ohook for permanent Office activation is installed.'; write-host -back 'Black' -fore 'Yellow' 'You can ignore below Office activation status.'" -echo. -) - -:casWcon -set winID=0 -set verbose=1 -if not defined c0ff1ce15 ( -if defined osppsvc goto :casWospp -goto :casWend -) -echo %line2% -echo *** Office Status *** -echo %line2% -set "_qr=%_zz7% %wspp% %_zz2% %_zz5%ApplicationID='%o15App%' and PartialProductKey is not null%_zz6% %_zz3% ID %_zz8%" -for /f "tokens=2 delims==" %%# in ('%_qr%') do ( - set "chkID=%%#" - call :casWdet "%wspp%" "%wsps%" "%spp_get%" - call :casWout - echo %line3% - echo. -) -set verbose=0 -if defined osppsvc goto :casWospp -goto :casWend - -:casWospp -if %verbose% EQU 1 ( -echo %line2% -echo *** Office Status *** -echo %line2% -) -set "_qr=%_zz7% %ospp% %_zz2% %_zz5%ApplicationID='%o15App%' and PartialProductKey is not null%_zz6% %_zz3% ID %_zz8%" -if defined ospp15 for /f "tokens=2 delims==" %%# in ('%_qr%') do ( - set "chkID=%%#" - call :casWdet "%ospp%" "%osps%" "%ospp_get%" - call :casWout - echo %line3% - echo. -) -set "_qr=%_zz7% %ospp% %_zz2% %_zz5%ApplicationID='%o14App%' and PartialProductKey is not null%_zz6% %_zz3% ID %_zz8%" -if defined ospp14 for /f "tokens=2 delims==" %%# in ('%_qr%') do ( - set "chkID=%%#" - call :casWdet "%ospp%" "%osps%" "%ospp_get%" - call :casWout - echo %line3% - echo. -) -goto :casWend - -:casWpkey -set "_qr=%_zz1% %1 %_zz2% %_zz5%ApplicationID='%2' and PartialProductKey is not null%_zz6% %_zz3% ID %_zz4%" -%_qr% 2>nul | findstr /i ID 1>nul && (set %3=1&set %4=1) -exit /b - -:casWdet -for %%# in (%~3) do set "%%#=" -if /i %~1==%ospp% for %%# in (DiscoveredKeyManagementServiceMachineIpAddress, KeyManagementServiceLookupDomain, ProductKeyChannel, VLActivationTypeEnabled) do set "%%#=" -set "cKmsClient=" -set "cTblClient=" -set "cAvmClient=" -set "ExpireMsg=" -set "_xpr=" -set "_qr="wmic path %~1 where ID='%chkID%' get %~3 /value" ^| findstr ^=" -if %WMI_VBS% NEQ 0 set "_qr=%_csg% %~1 "ID='%chkID%'" "%~3"" -for /f "tokens=* delims=" %%# in ('%_qr%') do set "%%#" - -set /a _gpr=(GracePeriodRemaining+1440-1)/1440 -echo %Description%| findstr /i VOLUME_KMSCLIENT 1>nul && (set cKmsClient=1&set _mTag=Volume) -echo %Description%| findstr /i TIMEBASED_ 1>nul && (set cTblClient=1&set _mTag=Timebased) -echo %Description%| findstr /i VIRTUAL_MACHINE_ACTIVATION 1>nul && (set cAvmClient=1&set _mTag=Automatic VM) -cmd /c exit /b %LicenseStatusReason% -set "LicenseReason=%=ExitCode%" -set "LicenseMsg=Time remaining: %GracePeriodRemaining% minute(s) (%_gpr% day(s))" -if %_gpr% GEQ 1 if %_WSH% EQU 1 ( -for /f "tokens=* delims=" %%# in ('%_csx% %GracePeriodRemaining%') do set "_xpr=%%#" -) -if %_gpr% GEQ 1 if %_prsh% EQU 1 if not defined _xpr ( -for /f "tokens=* delims=" %%# in ('%_psc% "$([DateTime]::Now.addMinutes(%GracePeriodRemaining%)).ToString('yyyy-MM-dd HH:mm:ss')" 2^>nul') do set "_xpr=%%#" -title Check Activation Status [wmi] -) - -if %LicenseStatus% EQU 0 ( -set "License=Unlicensed" -set "LicenseMsg=" -) -if %LicenseStatus% EQU 1 ( -set "License=Licensed" -set "LicenseMsg=" -if %GracePeriodRemaining% EQU 0 ( - if %winID% EQU 1 (set "ExpireMsg=The machine is permanently activated.") else (set "ExpireMsg=The product is permanently activated.") - ) else ( - set "LicenseMsg=%_mTag% activation expiration: %GracePeriodRemaining% minute(s) (%_gpr% day(s))" - if defined _xpr set "ExpireMsg=%_mTag% activation will expire %_xpr%" - ) -) -if %LicenseStatus% EQU 2 ( -set "License=Initial grace period" -if defined _xpr set "ExpireMsg=Initial grace period ends %_xpr%" -) -if %LicenseStatus% EQU 3 ( -set "License=Additional grace period (KMS license expired or hardware out of tolerance)" -if defined _xpr set "ExpireMsg=Additional grace period ends %_xpr%" -) -if %LicenseStatus% EQU 4 ( -set "License=Non-genuine grace period." -if defined _xpr set "ExpireMsg=Non-genuine grace period ends %_xpr%" -) -if %LicenseStatus% EQU 6 ( -set "License=Extended grace period" -if defined _xpr set "ExpireMsg=Extended grace period ends %_xpr%" -) -if %LicenseStatus% EQU 5 ( -set "License=Notification" - if "%LicenseReason%"=="C004F200" (set "LicenseMsg=Notification Reason: 0xC004F200 (non-genuine)." - ) else if "%LicenseReason%"=="C004F009" (set "LicenseMsg=Notification Reason: 0xC004F009 (grace time expired)." - ) else (set "LicenseMsg=Notification Reason: 0x%LicenseReason%" - ) -) -if %LicenseStatus% GTR 6 ( -set "License=Unknown" -set "LicenseMsg=" -) -if not defined cKmsClient exit /b - -if %KeyManagementServicePort%==0 set KeyManagementServicePort=1688 -set "KmsReg=Registered KMS machine name: %KeyManagementServiceMachine%:%KeyManagementServicePort%" -if "%KeyManagementServiceMachine%"=="" set "KmsReg=Registered KMS machine name: KMS name not available" - -if %DiscoveredKeyManagementServiceMachinePort%==0 set DiscoveredKeyManagementServiceMachinePort=1688 -set "KmsDns=KMS machine name from DNS: %DiscoveredKeyManagementServiceMachineName%:%DiscoveredKeyManagementServiceMachinePort%" -if "%DiscoveredKeyManagementServiceMachineName%"=="" set "KmsDns=DNS auto-discovery: KMS name not available" - -set "_qr="wmic path %~2 get ClientMachineID, KeyManagementServiceHostCaching /value" ^| findstr ^=" -if %WMI_VBS% NEQ 0 set "_qr=%_csg% %~2 "ClientMachineID, KeyManagementServiceHostCaching"" -for /f "tokens=* delims=" %%# in ('%_qr%') do set "%%#" -if /i %KeyManagementServiceHostCaching%==True (set KeyManagementServiceHostCaching=Enabled) else (set KeyManagementServiceHostCaching=Disabled) - -if %winbuild% LSS 9200 exit /b -if /i %~1==%ospp% exit /b - -if "%KeyManagementServiceLookupDomain%"=="" set "KeyManagementServiceLookupDomain=" - -if %VLActivationTypeEnabled% EQU 3 ( -set VLActivationType=Token -) else if %VLActivationTypeEnabled% EQU 2 ( -set VLActivationType=KMS -) else if %VLActivationTypeEnabled% EQU 1 ( -set VLActivationType=AD -) else ( -set VLActivationType=All -) - -if %winbuild% LSS 9600 exit /b -if "%DiscoveredKeyManagementServiceMachineIpAddress%"=="" set "DiscoveredKeyManagementServiceMachineIpAddress=not available" -exit /b - -:casWout -echo. -echo Name: %Name% -echo Description: %Description% -echo Activation ID: %ID% -echo Extended PID: %ProductKeyID% -if defined ProductKeyChannel echo Product Key Channel: %ProductKeyChannel% -echo Partial Product Key: %PartialProductKey% -echo License Status: %License% -if defined LicenseMsg echo %LicenseMsg% -if not %LicenseStatus%==0 if not %EvaluationEndDate:~0,8%==16010101 echo Evaluation End Date: %EvaluationEndDate:~0,4%-%EvaluationEndDate:~4,2%-%EvaluationEndDate:~6,2% %EvaluationEndDate:~8,2%:%EvaluationEndDate:~10,2% UTC -if not defined cKmsClient ( -if defined ExpireMsg echo.&echo. %ExpireMsg% -exit /b -) -if defined VLActivationTypeEnabled echo Configured Activation Type: %VLActivationType% -echo. -if not %LicenseStatus%==1 ( -echo Please activate the product in order to update KMS client information values. -exit /b -) -echo Most recent activation information: -echo Key Management Service client information -echo. Client Machine ID (CMID): %ClientMachineID% -echo. %KmsDns% -echo. %KmsReg% -if defined DiscoveredKeyManagementServiceMachineIpAddress echo. KMS machine IP address: %DiscoveredKeyManagementServiceMachineIpAddress% -echo. KMS machine extended PID: %KeyManagementServiceProductKeyID% -echo. Activation interval: %VLActivationInterval% minutes -echo. Renewal interval: %VLRenewalInterval% minutes -echo. K.M.S host caching: %KeyManagementServiceHostCaching% -if defined KeyManagementServiceLookupDomain echo. KMS SRV record lookup domain: %KeyManagementServiceLookupDomain% -if defined ExpireMsg echo.&echo. %ExpireMsg% -exit /b - -:casWend -if %_Identity% EQU 1 if %_prsh% EQU 1 ( -echo %line2% -echo *** Office vNext Status *** -echo %line2% -setlocal EnableDelayedExpansion -%_psc% "$f=[IO.File]::ReadAllText('!_batp!') -split ':vNextDiag\:.*';iex ($f[1])" -title Check Activation Status [wmi] -echo %line3% -echo. -) -echo. -echo Press any key to exit. -pause >nul -exit /b - -:vNextDiag: -function PrintModePerPridFromRegistry -{ - $vNextRegkey = "HKCU:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing\LicensingNext" - $vNextPrids = Get-Item -Path $vNextRegkey -ErrorAction Ignore | Select-Object -ExpandProperty 'property' | Where-Object -FilterScript {$_.ToLower() -like "*retail" -or $_.ToLower() -like "*volume"} - If ($vNextPrids -Eq $null) - { - Write-Host "No registry keys found." - Return - } - $vNextPrids | ForEach ` - { - $mode = (Get-ItemProperty -Path $vNextRegkey -Name $_).$_ - Switch ($mode) - { - 2 { $mode = "vNext"; Break } - 3 { $mode = "Device"; Break } - Default { $mode = "Legacy"; Break } - } - Write-Host $_ = $mode - } -} -function PrintSharedComputerLicensing -{ - $scaRegKey = "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration" - $scaValue = Get-ItemProperty -Path $scaRegKey -ErrorAction Ignore | Select-Object -ExpandProperty "SharedComputerLicensing" -ErrorAction Ignore - $scaRegKey2 = "HKLM:\SOFTWARE\Microsoft\Office\16.0\Common\Licensing" - $scaValue2 = Get-ItemProperty -Path $scaRegKey2 -ErrorAction Ignore | Select-Object -ExpandProperty "SharedComputerLicensing" -ErrorAction Ignore - $scaPolicyKey = "HKLM:\SOFTWARE\Policies\Microsoft\Office\16.0\Common\Licensing" - $scaPolicyValue = Get-ItemProperty -Path $scaPolicyKey -ErrorAction Ignore | Select-Object -ExpandProperty "SharedComputerLicensing" -ErrorAction Ignore - If ($scaValue -Eq $null -And $scaValue2 -Eq $null -And $scaPolicyValue -Eq $null) - { - Write-Host "No registry keys found." - Return - } - $scaModeValue = $scaValue -Or $scaValue2 -Or $scaPolicyValue - If ($scaModeValue -Eq 0) - { - $scaMode = "Disabled" - } - If ($scaModeValue -Eq 1) - { - $scaMode = "Enabled" - } - Write-Host "SharedComputerLicensing" = $scaMode - Write-Host - $tokenFiles = $null - $tokenPath = "${env:LOCALAPPDATA}\Microsoft\Office\16.0\Licensing" - If (Test-Path $tokenPath) - { - $tokenFiles = Get-ChildItem -Path $tokenPath -Recurse -File -Filter "*authString*" - } - If ($tokenFiles.length -Eq 0) - { - Write-Host "No tokens found." - Return - } - $tokenFiles | ForEach ` - { - $tokenParts = (Get-Content -Encoding Unicode -Path $_.FullName).Split('_') - $output = [PSCustomObject] ` - @{ - ACID = $tokenParts[0]; - User = $tokenParts[3] - NotBefore = $tokenParts[4]; - NotAfter = $tokenParts[5]; - } | ConvertTo-Json - Write-Host $output - } -} -function PrintLicensesInformation -{ - Param( - [ValidateSet("NUL", "Device")] - [String]$mode - ) - If ($mode -Eq "NUL") - { - $licensePath = "${env:LOCALAPPDATA}\Microsoft\Office\Licenses" - } - ElseIf ($mode -Eq "Device") - { - $licensePath = "${env:PROGRAMDATA}\Microsoft\Office\Licenses" - } - $licenseFiles = $null - If (Test-Path $licensePath) - { - $licenseFiles = Get-ChildItem -Path $licensePath -Recurse -File - } - If ($licenseFiles.length -Eq 0) - { - Write-Host "No licenses found." - 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 -Ne $decodedLicense.ExpiresOn) - { - $expiry = [DateTime]::Parse($decodedLicense.ExpiresOn, $null, 48) - } - Else - { - $expiry = New-Object DateTime - } - $licenseState = $null - If ((Get-Date) -Gt (Get-Date $decodedLicense.MetaData.NotAfter)) - { - $licenseState = "RFM" - } - ElseIf ((Get-Date) -Lt (Get-Date $expiry)) - { - $licenseState = "Licensed" - } - Else - { - $licenseState = "Grace" - } - if ($mode -Eq "NUL") - { - $output = [PSCustomObject] ` - @{ - Version = $_.Directory.Name - Type = "User|${licenseType}"; - Product = $decodedLicense.ProductReleaseId; - Acid = $decodedLicense.Acid; - LicenseState = $licenseState; - EntitlementStatus = $decodedLicense.Status; - EntitlementExpiration = $decodedLicense.ExpiresOn; - ReasonCode = $decodedLicense.ReasonCode; - NotBefore = $decodedLicense.Metadata.NotBefore; - NotAfter = $decodedLicense.Metadata.NotAfter; - NextRenewal = $decodedLicense.Metadata.RenewAfter; - TenantId = $decodedLicense.Metadata.TenantId; - } | ConvertTo-Json - } - ElseIf ($mode -Eq "Device") - { - $output = [PSCustomObject] ` - @{ - Version = $_.Directory.Name - Type = "Device|${licenseType}"; - Product = $decodedLicense.ProductReleaseId; - Acid = $decodedLicense.Acid; - DeviceId = $decodedLicense.Metadata.DeviceId; - LicenseState = $licenseState; - EntitlementStatus = $decodedLicense.Status; - EntitlementExpiration = $decodedLicense.ExpiresOn; - ReasonCode = $decodedLicense.ReasonCode; - NotBefore = $decodedLicense.Metadata.NotBefore; - NotAfter = $decodedLicense.Metadata.NotAfter; - NextRenewal = $decodedLicense.Metadata.RenewAfter; - TenantId = $decodedLicense.Metadata.TenantId; - } | ConvertTo-Json - } - Write-Output $output - } -} - Write-Host - Write-Host "========== Mode per ProductReleaseId ==========" - Write-Host -PrintModePerPridFromRegistry - Write-Host - Write-Host "========== Shared Computer Licensing ==========" - Write-Host -PrintSharedComputerLicensing - Write-Host - Write-Host "========== vNext licenses ==========" - Write-Host -PrintLicensesInformation -Mode "NUL" - Write-Host - Write-Host "========== Device licenses ==========" - Write-Host -PrintLicensesInformation -Mode "Device" -:vNextDiag: -::=================================================== -:: Leave empty line below diff --git a/MAS/Separate-Files-Version/Check-Activation-Status.cmd b/MAS/Separate-Files-Version/Check-Activation-Status.cmd new file mode 100644 index 0000000..02bedad --- /dev/null +++ b/MAS/Separate-Files-Version/Check-Activation-Status.cmd @@ -0,0 +1,1025 @@ +@echo off + + +:: Check-Activation-Status +:: Written by @abbodi1406 +:: https://gravesoft.dev/cas + + +set "Path=%SystemRoot%\System32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SystemRoot%\System32\WindowsPowerShell\v1.0\" +if exist "%SystemRoot%\Sysnative\reg.exe" ( +set "Path=%SystemRoot%\Sysnative;%SystemRoot%;%SystemRoot%\Sysnative\Wbem;%SystemRoot%\Sysnative\WindowsPowerShell\v1.0\;%Path%" +) +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. +echo Press any key to exit. +pause >nul +exit /b + +:sppmgr: +function ExitScript($ExitCode = 0) +{ + Exit $ExitCode +} + +if (-Not $PSVersionTable) { + Write-Host "==== ERROR ====`r`n" + Write-Host 'Windows PowerShell 1.0 is not supported by this script.' + ExitScript 1 +} + +if ($ExecutionContext.SessionState.LanguageMode.value__ -NE 0) { + Write-Host "==== ERROR ====`r`n" + Write-Host 'Windows PowerShell is not running in Full Language Mode.' + ExitScript 1 +} + +$winbuild = 1 +try { + $winbuild = [System.Diagnostics.FileVersionInfo]::GetVersionInfo("$env:SystemRoot\System32\kernel32.dll").FileBuildPart +} catch { + $winbuild = [int](Get-WmiObject Win32_OperatingSystem).BuildNumber +} + +if ($winbuild -EQ 1) { + Write-Host "==== ERROR ====`r`n" + Write-Host 'Could not detect Windows build.' + ExitScript 1 +} + +if ($winbuild -LT 2600) { + Write-Host "==== ERROR ====`r`n" + Write-Host 'This build of Windows is not supported by this script.' + ExitScript 1 +} + +$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 = "____________________________________________________________" + +function echoWindows +{ + Write-Host "$line2" + Write-Host "=== Windows Status ===" + Write-Host "$line2" + if (!$All.IsPresent) {Write-Host} +} + +function echoOffice +{ + if ($doMSG -EQ 0) { + return + } + + if ($All.IsPresent) {Write-Host} + Write-Host "$line2" + Write-Host "=== Office Status ===" + Write-Host "$line2" + if (!$All.IsPresent) {Write-Host} + + $script:doMSG = 0 +} + +function strGetRegistry($strKey, $strName) +{ +Get-ItemProperty -EA 0 $strKey | select -EA 0 -Expand $strName +} + +function CheckOhook +{ + $ohook = 0 + $paths = "${env:ProgramFiles}", "${env:ProgramW6432}", "${env:ProgramFiles(x86)}" + + 15, 16 | foreach ` + { + $A = $_; $paths | foreach ` + { + if (Test-Path "$($_)$('\Microsoft Office\Office')$($A)$('\sppc*dll')") {$ohook = 1} + } + } + + "System", "SystemX86" | foreach ` + { + $A = $_; "Office 15", "Office" | foreach ` + { + $B = $_; $paths | foreach ` + { + if (Test-Path "$($_)$('\Microsoft ')$($B)$('\root\vfs\')$($A)$('\sppc*dll')") {$ohook = 1} + } + } + } + + if ($ohook -EQ 0) { + return + } + + if ($All.IsPresent) {Write-Host} + Write-Host "$line2" + Write-Host "=== Office Ohook Status ===" + Write-Host "$line2" + Write-Host + Write-Host -back 'Black' -fore 'Yellow' 'Ohook for permanent Office activation is installed.' + Write-Host -back 'Black' -fore 'Yellow' 'You can ignore the below mentioned Office activation status.' + if (!$All.IsPresent) {Write-Host} +} + +#region WMI +function DetectID($strSLP, $strAppId, [ref]$strAppVar) +{ + $fltr = "ApplicationID='$strAppId'" + if (!$All.IsPresent) { + $fltr = $fltr + " AND PartialProductKey <> NULL" + } + Get-WmiObject $strSLP ID -Filter $fltr -EA 0 | select ID -EA 0 | foreach { + $strAppVar.Value = 1 + } +} + +function GetID($strSLP, $strAppId, $strProperty = "ID") +{ + $NT5 = ($strSLP -EQ $wslp -And $winbuild -LT 6001) + $IDs = [Collections.ArrayList]@() + + if ($All.IsPresent) { + $fltr = "ApplicationID='$strAppId' AND PartialProductKey IS NULL" + $clause = $fltr + if (-Not $NT5) { + $clause = $fltr + " AND LicenseDependsOn <> NULL" + } + Get-WmiObject $strSLP $strProperty -Filter $clause -EA 0 | select -Expand $strProperty -EA 0 | foreach {$IDs += $_} + if (-Not $NT5) { + $clause = $fltr + " AND LicenseDependsOn IS NULL" + Get-WmiObject $strSLP $strProperty -Filter $clause -EA 0 | select -Expand $strProperty -EA 0 | foreach {$IDs += $_} + } + } + + $fltr = "ApplicationID='$strAppId' AND PartialProductKey <> NULL" + $clause = $fltr + if (-Not $NT5) { + $clause = $fltr + " AND LicenseDependsOn <> NULL" + } + Get-WmiObject $strSLP $strProperty -Filter $clause -EA 0 | select -Expand $strProperty -EA 0 | foreach {$IDs += $_} + if (-Not $NT5) { + $clause = $fltr + " AND LicenseDependsOn IS NULL" + Get-WmiObject $strSLP $strProperty -Filter $clause -EA 0 | select -Expand $strProperty -EA 0 | foreach {$IDs += $_} + } + + return $IDs +} + +function DetectSubscription { + if ($null -EQ $objSvc.SubscriptionType -Or $objSvc.SubscriptionType -EQ 120) { + return + } + + if ($objSvc.SubscriptionType -EQ 1) { + $SubMsgType = "Device based" + } else { + $SubMsgType = "User based" + } + + if ($objSvc.SubscriptionStatus -EQ 120) { + $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") -EQ $false) {$SubMsgExpiry = $objSvc.SubscriptionExpiry} + } + + $SubMsgEdition = "Unknown" + if ($objSvc.SubscriptionEdition) { + if ($objSvc.SubscriptionEdition.Contains("UNKNOWN") -EQ $false) {$SubMsgEdition = $objSvc.SubscriptionEdition} + } + + Write-Host + Write-Host "Subscription information:" + Write-Host " Edition: $SubMsgEdition" + Write-Host " Type : $SubMsgType" + Write-Host " Status : $SubMsgStatus" + Write-Host " Expiry : $SubMsgExpiry" +} + +function DetectAvmClient +{ + Write-Host + Write-Host "Automatic VM Activation client information:" + if (-Not [String]::IsNullOrEmpty($IAID)) { + Write-Host " Guest IAID: $IAID" + } else { + Write-Host " Guest IAID: Not Available" + } + if (-Not [String]::IsNullOrEmpty($AutomaticVMActivationHostMachineName)) { + Write-Host " Host machine name: $AutomaticVMActivationHostMachineName" + } else { + Write-Host " Host machine name: Not Available" + } + if ($AutomaticVMActivationLastActivationTime.Substring(0,4) -NE "1601") { + $EED = [DateTime]::Parse([Management.ManagementDateTimeConverter]::ToDateTime($AutomaticVMActivationLastActivationTime),$null,48).ToString('yyyy-MM-dd hh:mm:ss tt') + Write-Host " Activation time: $EED UTC" + } else { + Write-Host " Activation time: Not Available" + } + if (-Not [String]::IsNullOrEmpty($AutomaticVMActivationHostDigitalPid2)) { + Write-Host " Host Digital PID2: $AutomaticVMActivationHostDigitalPid2" + } else { + Write-Host " Host Digital PID2: Not Available" + } +} + +function DetectKmsHost +{ + if ($Vista -Or $NT5) { + $KeyManagementServiceListeningPort = strGetRegistry $SLKeyPath "KeyManagementServiceListeningPort" + $KeyManagementServiceDnsPublishing = strGetRegistry $SLKeyPath "DisableDnsPublishing" + $KeyManagementServiceLowPriority = strGetRegistry $SLKeyPath "EnableKmsLowPriority" + if (-Not $KeyManagementServiceDnsPublishing) {$KeyManagementServiceDnsPublishing = "TRUE"} + if (-Not $KeyManagementServiceLowPriority) {$KeyManagementServiceLowPriority = "FALSE"} + } else { + $KeyManagementServiceListeningPort = $objSvc.KeyManagementServiceListeningPort + $KeyManagementServiceDnsPublishing = $objSvc.KeyManagementServiceDnsPublishing + $KeyManagementServiceLowPriority = $objSvc.KeyManagementServiceLowPriority + } + + if (-Not $KeyManagementServiceListeningPort) {$KeyManagementServiceListeningPort = 1688} + if ($KeyManagementServiceDnsPublishing -EQ "TRUE") { + $KeyManagementServiceDnsPublishing = "Enabled" + } else { + $KeyManagementServiceDnsPublishing = "Disabled" + } + if ($KeyManagementServiceLowPriority -EQ "TRUE") { + $KeyManagementServiceLowPriority = "Low" + } else { + $KeyManagementServiceLowPriority = "Normal" + } + + Write-Host + Write-Host "Key Management Service host information:" + Write-Host " Current count: $KeyManagementServiceCurrentCount" + Write-Host " Listening on Port: $KeyManagementServiceListeningPort" + Write-Host " DNS publishing: $KeyManagementServiceDnsPublishing" + Write-Host " KMS priority: $KeyManagementServiceLowPriority" + if (-Not [String]::IsNullOrEmpty($KeyManagementServiceTotalRequests)) { + Write-Host + Write-Host "Key Management Service cumulative requests received from clients:" + Write-Host " Total: $KeyManagementServiceTotalRequests" + Write-Host " Failed: $KeyManagementServiceFailedRequests" + Write-Host " Unlicensed: $KeyManagementServiceUnlicensedRequests" + Write-Host " Licensed: $KeyManagementServiceLicensedRequests" + Write-Host " Initial grace period: $KeyManagementServiceOOBGraceRequests" + Write-Host " Expired or Hardware out of tolerance: $KeyManagementServiceOOTGraceRequests" + Write-Host " Non-genuine grace period: $KeyManagementServiceNonGenuineGraceRequests" + Write-Host " Notification: $KeyManagementServiceNotificationRequests" + } +} + +function DetectKmsClient +{ + if ($null -NE $VLActivationTypeEnabled) {Write-Host "Configured Activation Type: $($VLActTypes[$VLActivationTypeEnabled])"} + Write-Host + if ($LicenseStatus -NE 1) { + Write-Host "Please activate the product in order to update KMS client information values." + return + } + + if ($Vista) { + $KeyManagementServicePort = strGetRegistry $SLKeyPath "KeyManagementServicePort" + $DiscoveredKeyManagementServiceMachineName = strGetRegistry $NSKeyPath "DiscoveredKeyManagementServiceName" + $DiscoveredKeyManagementServiceMachinePort = strGetRegistry $NSKeyPath "DiscoveredKeyManagementServicePort" + } + + if ([String]::IsNullOrEmpty($KeyManagementServiceMachine)) { + $KmsReg = $null + } else { + if (-Not $KeyManagementServicePort) {$KeyManagementServicePort = 1688} + $KmsReg = "Registered KMS machine name: ${KeyManagementServiceMachine}:${KeyManagementServicePort}" + } + + if ([String]::IsNullOrEmpty($DiscoveredKeyManagementServiceMachineName)) { + $KmsDns = "DNS auto-discovery: KMS name not available" + if ($Vista -And -Not $Admin) {$KmsDns = "DNS auto-discovery: Run the script as administrator to retrieve info"} + } else { + if (-Not $DiscoveredKeyManagementServiceMachinePort) {$DiscoveredKeyManagementServiceMachinePort = 1688} + $KmsDns = "KMS machine name from DNS: ${DiscoveredKeyManagementServiceMachineName}:${DiscoveredKeyManagementServiceMachinePort}" + } + + if ($null -NE $objSvc.KeyManagementServiceHostCaching) { + if ($objSvc.KeyManagementServiceHostCaching -EQ "TRUE") { + $KeyManagementServiceHostCaching = "Enabled" + } else { + $KeyManagementServiceHostCaching = "Disabled" + } + } + + Write-Host "Key Management Service client information:" + Write-Host " Client Machine ID (CMID): $($objSvc.ClientMachineID)" + if ($null -EQ $KmsReg) { + Write-Host " $KmsDns" + Write-Host " Registered KMS machine name: KMS name not available" + } else { + Write-Host " $KmsReg" + } + if ($null -NE $DiscoveredKeyManagementServiceMachineIpAddress) {Write-Host " KMS machine IP address: $DiscoveredKeyManagementServiceMachineIpAddress"} + Write-Host " KMS machine extended PID: $KeyManagementServiceProductKeyID" + Write-Host " Activation interval: $VLActivationInterval minutes" + Write-Host " Renewal interval: $VLRenewalInterval minutes" + if ($null -NE $KeyManagementServiceHostCaching) {Write-Host " KMS host caching: $KeyManagementServiceHostCaching"} + if (-Not [String]::IsNullOrEmpty($KeyManagementServiceLookupDomain)) {Write-Host " KMS SRV record lookup domain: $KeyManagementServiceLookupDomain"} +} + +function GetResult($strSLP, $strSLS, $strID) +{ + try {$objPrd = Get-WmiObject $strSLP -Filter "ID='$strID'" -EA 1} catch {return} + $objPrd | select -Expand Properties -EA 0 | foreach { + if (-Not [String]::IsNullOrEmpty($_.Value)) {set $_.Name $_.Value} + } + + $winID = ($ApplicationID -EQ $winApp) + $winPR = ($winID -And -Not $LicenseIsAddon) + $Vista = ($winID -And $NT6 -And -Not $NT7) + $NT5 = ($strSLP -EQ $wslp -And $winbuild -LT 6001) + + if ($Description | Select-String "VOLUME_KMSCLIENT") {$cKmsClient = 1; $_mTag = "Volume"} + if ($Description | Select-String "TIMEBASED_") {$cTblClient = 1; $_mTag = "Timebased"} + if ($Description | Select-String "VIRTUAL_MACHINE_ACTIVATION") {$cAvmClient = 1; $_mTag = "Automatic VM"} + if ($null -EQ $cKmsClient) { + if ($Description | Select-String "VOLUME_KMS") {$cKmsHost = 1} + } + + $_gpr = [Math]::Round($GracePeriodRemaining/1440) + if ($_gpr -GT 0) { + $_xpr = [DateTime]::Now.addMinutes($GracePeriodRemaining).ToString('yyyy-MM-dd hh:mm:ss tt') + } + + if ($null -EQ $LicenseStatusReason) {$LicenseStatusReason = -1} + $LicenseReason = '0x{0:X}' -f $LicenseStatusReason + $LicenseMsg = "Time remaining: $GracePeriodRemaining minute(s) ($_gpr day(s))" + if ($LicenseStatus -EQ 0) { + $LicenseInf = "Unlicensed" + $LicenseMsg = $null + } + if ($LicenseStatus -EQ 1) { + $LicenseInf = "Licensed" + $LicenseMsg = $null + if ($GracePeriodRemaining -EQ 0) { + if ($winPR) {$ExpireMsg = "The machine is permanently activated."} else {$ExpireMsg = "The product is permanently activated."} + } else { + $LicenseMsg = "$_mTag activation expiration: $GracePeriodRemaining minute(s) ($_gpr day(s))" + if ($null -NE $_xpr) {$ExpireMsg = "$_mTag activation will expire $_xpr"} + } + } + if ($LicenseStatus -EQ 2) { + $LicenseInf = "Initial grace period" + if ($null -NE $_xpr) {$ExpireMsg = "Initial grace period ends $_xpr"} + } + if ($LicenseStatus -EQ 3) { + $LicenseInf = "Additional grace period (KMS license expired or hardware out of tolerance)" + if ($null -NE $_xpr) {$ExpireMsg = "Additional grace period ends $_xpr"} + } + if ($LicenseStatus -EQ 4) { + $LicenseInf = "Non-genuine grace period" + if ($null -NE $_xpr) {$ExpireMsg = "Non-genuine grace period ends $_xpr"} + } + if ($LicenseStatus -EQ 5 -And -Not $NT5) { + $LicenseInf = "Notification" + $LicenseMsg = "Notification Reason: $LicenseReason" + if ($LicenseReason -EQ "0xC004F200") {$LicenseMsg = $LicenseMsg + " (non-genuine)."} + if ($LicenseReason -EQ "0xC004F009") {$LicenseMsg = $LicenseMsg + " (grace time expired)."} + } + if ($LicenseStatus -GT 5 -Or ($LicenseStatus -GT 4 -And $NT5)) { + $LicenseInf = "Unknown" + $LicenseMsg = $null + } + if ($LicenseStatus -EQ 6 -And -Not $Vista -And -Not $NT5) { + $LicenseInf = "Extended grace period" + if ($null -NE $_xpr) {$ExpireMsg = "Extended grace period ends $_xpr"} + } + + if ($winPR -And $PartialProductKey -And -Not $NT9) { + $dp4 = Get-ItemProperty -EA 0 "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion" | select -EA 0 -Expand DigitalProductId4 + if ($null -NE $dp4) { + $ProductKeyChannel = ([System.Text.Encoding]::Unicode.GetString($dp4, 1016, 128)).Trim([char]$null) + } + } + + if ($All.IsPresent) {Write-Host} + Write-Host "Name: $Name" + Write-Host "Description: $Description" + Write-Host "Activation ID: $ID" + if ($null -NE $ProductKeyID) {Write-Host "Extended PID: $ProductKeyID"} + if ($null -NE $OfflineInstallationId -And $IID.IsPresent) {Write-Host "Installation ID: $OfflineInstallationId"} + if ($null -NE $ProductKeyChannel) {Write-Host "Product Key Channel: $ProductKeyChannel"} + if ($null -NE $PartialProductKey) {Write-Host "Partial Product Key: $PartialProductKey"} else {Write-Host "Product Key: Not installed"} + Write-Host "License Status: $LicenseInf" + if ($null -NE $LicenseMsg) {Write-Host "$LicenseMsg"} + if ($LicenseStatus -NE 0 -And $EvaluationEndDate.Substring(0,4) -NE "1601") { + $EED = [DateTime]::Parse([Management.ManagementDateTimeConverter]::ToDateTime($EvaluationEndDate),$null,48).ToString('yyyy-MM-dd hh:mm:ss tt') + Write-Host "Evaluation End Date: $EED UTC" + } + + if ($winID -And $null -NE $cAvmClient -And $null -NE $PartialProductKey) { + DetectAvmClient + } + + $chkSub = ($winPR -And $cSub) + + $chkSLS = ($null -NE $PartialProductKey) -And ($null -NE $cKmsClient -Or $null -NE $cKmsHost -Or $chkSub) + + if (!$chkSLS) { + if ($null -NE $ExpireMsg) {Write-Host; Write-Host " $ExpireMsg"} + return + } + + $objSvc = Get-WmiObject $strSLS -EA 0 + + if ($Vista) { + $objSvc | select -Expand Properties -EA 0 | foreach { + if (-Not [String]::IsNullOrEmpty($_.Value)) {set $_.Name $_.Value} + } + } + + if ($strSLS -EQ $wsls -And $NT9) { + if ([String]::IsNullOrEmpty($DiscoveredKeyManagementServiceMachineIpAddress)) { + $DiscoveredKeyManagementServiceMachineIpAddress = "not available" + } + } + + if ($null -NE $cKmsHost -And $IsKeyManagementServiceMachine -GT 0) { + DetectKmsHost + } + + if ($null -NE $cKmsClient) { + DetectKmsClient + } + + if ($null -NE $ExpireMsg) {Write-Host; Write-Host " $ExpireMsg"} + + if ($chkSub) { + DetectSubscription + } + +} +#endregion + +#region vNextDiag +if ($PSVersionTable.PSVersion.Major -Lt 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 -Eq $vNextPrids) + { + Write-Host + Write-Host "No registry keys found." + Return + } + Write-Host + $vNextPrids | ForEach ` + { + $mode = (Get-ItemProperty -Path $vNextRegkey -Name $_).$_ + Switch ($mode) + { + 2 { $mode = "vNext"; Break } + 3 { $mode = "Device"; Break } + Default { $mode = "Legacy"; Break } + } + Write-Host $_ = $mode + } +} + +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 -Eq $scaValue -And $null -Eq $scaValue2 -And $null -Eq $scaPolicyValue) + { + Write-Host + Write-Host "No registry keys found." + Return + } + $scaModeValue = $scaValue -Or $scaValue2 -Or $scaPolicyValue + If ($scaModeValue -Eq 0) + { + $scaMode = "Disabled" + } + If ($scaModeValue -Eq 1) + { + $scaMode = "Enabled" + } + Write-Host + Write-Host "Status:" $scaMode + Write-Host + $tokenFiles = $null + $tokenPath = "${env:LOCALAPPDATA}\Microsoft\Office\16.0\Licensing" + If (Test-Path $tokenPath) + { + $tokenFiles = Get-ChildItem -Path $tokenPath -Filter "*authString*" -Recurse | Where-Object { !$_.PSIsContainer } + } + If ($null -Eq $tokenFiles) + { + Write-Host "No tokens found." + Return + } + If ($tokenFiles.Length -Eq 0) + { + Write-Host "No tokens found." + 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 -Eq "NUL") + { + $licensePath = "${env:LOCALAPPDATA}\Microsoft\Office\Licenses" + } + ElseIf ($mode -Eq "Device") + { + $licensePath = "${env:PROGRAMDATA}\Microsoft\Office\Licenses" + } + $licenseFiles = $null + If (Test-Path $licensePath) + { + $licenseFiles = Get-ChildItem -Path $licensePath -Recurse | Where-Object { !$_.PSIsContainer } + } + If ($null -Eq $licenseFiles) + { + Write-Host + Write-Host "No licenses found." + Return + } + If ($licenseFiles.Length -Eq 0) + { + Write-Host + Write-Host "No licenses found." + 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 -Ne $decodedLicense.ExpiresOn) + { + $expiry = [System.DateTime]::Parse($decodedLicense.ExpiresOn, $null, 'AdjustToUniversal') + } + Else + { + $expiry = New-Object System.DateTime + } + $licenseState = "Grace" + If ((Get-Date) -Gt (Get-Date $decodedLicense.Metadata.NotAfter)) + { + $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 -Eq "Device") { $output | Add-Member 8 'DeviceId' $decodedLicense.Metadata.DeviceId; } + $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 -Or $fDev -Or $rPID -Or $rSCA -Or $rSCL) -EQ $false) { + Return + } + + if ($All.IsPresent) {Write-Host} + Write-Host "$line2" + Write-Host "=== Office vNext Status ===" + Write-Host "$line2" + Write-Host + Write-Host "========== Mode per ProductReleaseId ==========" + PrintModePerPridFromRegistry + Write-Host + Write-Host "========== Shared Computer Licensing ==========" + PrintSharedComputerLicensing + Write-Host + Write-Host "========== vNext licenses ===========" + PrintLicensesInformation -Mode "NUL" + Write-Host + Write-Host "========== Device licenses ==========" + PrintLicensesInformation -Mode "Device" + Write-Host "$line3" + Write-Host +} +#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 " + Write-Host " $pwszStateString" + + $Marshal::FreeHGlobal($pwszStateData) + return $TRUE +} + +function PrintLastActivationHRresult { + $pdwLastHResult = 0 + $cbSize = 0 + + if ($Win32::SLGetWindowsInformation( + "Security-SPP-LastWindowsActivationHResult", + [ref]$null, + [ref]$cbSize, + [ref]$pdwLastHResult + )) { + return $FALSE + } + + Write-Host (" LastActivationHResult=0x{0:x8}" -f $Marshal::ReadInt32($pdwLastHResult)) + + $Marshal::FreeHGlobal($pdwLastHResult) + return $TRUE +} + +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 -lt 5) { + Write-Host (" IsWindowsGenuine={0}" -f $ppwszGenuineStates[$dwGenuine]) + } else { + Write-Host (" IsWindowsGenuine={0}" -f $dwGenuine) + } + + 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, $parameters)) { + return $FALSE + } + + $dwReturnCode = $parameters[1] + [bool]$bDigitalLicense = $FALSE + + $bDigitalLicense = (($dwReturnCode -ge 0) -and ($dwReturnCode -ne 1)) + Write-Host (" IsDigitalLicense={0}" -f (BoolToWStr $bDigitalLicense)) + + return $TRUE +} + +function PrintSubscriptionStatus { + $dwSupported = 0 + + if ($winbuild -ge 15063) { + $pwszPolicy = "ConsumeAddonPolicySet" + } else { + $pwszPolicy = "Allow-WindowsSubscription" + } + + if ($Win32::SLGetWindowsInformationDWORD($pwszPolicy, [ref]$dwSupported)) { + return $FALSE + } + + Write-Host (" SubscriptionSupportedEdition={0}" -f (BoolToWStr $dwSupported)) + + $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) + + Write-Host (" SubscriptionEnabled={0}" -f (BoolToWStr $sStatus.dwEnabled)) + + if ($sStatus.dwEnabled -eq 0) { + return $TRUE + } + + Write-Host (" SubscriptionSku={0}" -f $sStatus.dwSku) + Write-Host (" SubscriptionState={0}" -f $sStatus.dwState) + + return $TRUE +} + +function ClicRun +{ + if ($All.IsPresent) {Write-Host} + Write-Host "Client Licensing Check information:" + + $null = PrintStateData + $null = PrintLastActivationHRresult + $null = PrintIsWindowsGenuine + + if ($DllDigital) { + $null = PrintDigitalLicenseStatus + } + + if ($DllSubscription) { + $null = PrintSubscriptionStatus + } + + Write-Host "$line3" + if (!$All.IsPresent) {Write-Host} +} +#endregion + +$Host.UI.RawUI.WindowTitle = "Check Activation Status" + +if ($All.IsPresent) { + $B=$Host.UI.RawUI.BufferSize;$B.Height=3000;$Host.UI.RawUI.BufferSize=$B;clear; +} + +$SysPath = "$env:SystemRoot\System32" +if (Test-Path "$env:SystemRoot\Sysnative\reg.exe") { + $SysPath = "$env:SystemRoot\Sysnative" +} + +$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") +$SLKeyPath = "Registry::HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SL" +$NSKeyPath = "Registry::HKEY_USERS\S-1-5-20\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SL" + +'cW1nd0ws', 'c0ff1ce15', 'c0ff1ce14', 'ospp14', 'ospp15' | foreach {set $_ $null} + +$OsppHook = 1 +try {gsv osppsvc -EA 1 | Out-Null} catch {$OsppHook = 0} + +if ($NT7 -Or -Not $NT6) { + try {sasv sppsvc -EA 1} catch {} +} +else +{ + try {sasv slsvc -EA 1} catch {} +} + +DetectID $wslp $winApp ([ref]$cW1nd0ws) +DetectID $wslp $o15App ([ref]$c0ff1ce15) +DetectID $wslp $o14App ([ref]$c0ff1ce14) + +if ($OsppHook -NE 0) { + try {sasv osppsvc -EA 1} catch {} + DetectID $oslp $o15App ([ref]$ospp15) + DetectID $oslp $o14App ([ref]$ospp14) +} + +if ($null -NE $cW1nd0ws) +{ + echoWindows + GetID $wslp $winApp | foreach -EA 1 { + GetResult $wslp $wsls $_ + Write-Host "$line3" + if (!$All.IsPresent) {Write-Host} + } +} +elseif ($NT6) +{ + echoWindows + Write-Host + Write-Host "Error: product key not found." +} + +if ($winbuild -GE 9200) { + . InitializePInvoke + ClicRun +} + +if ($c0ff1ce15 -Or $ospp15) { + CheckOhook +} + +$doMSG = 1 + +if ($null -NE $c0ff1ce15) { + echoOffice + GetID $wslp $o15App | foreach -EA 1 { + GetResult $wslp $wsls $_ + Write-Host "$line3" + if (!$All.IsPresent) {Write-Host} + } +} + +if ($null -NE $c0ff1ce14) { + echoOffice + GetID $wslp $o14App | foreach -EA 1 { + GetResult $wslp $wsls $_ + Write-Host "$line3" + if (!$All.IsPresent) {Write-Host} + } +} + +if ($null -NE $ospp15) { + echoOffice + GetID $oslp $o15App | foreach -EA 1 { + GetResult $oslp $osls $_ + Write-Host "$line3" + if (!$All.IsPresent) {Write-Host} + } +} + +if ($null -NE $ospp14) { + echoOffice + GetID $oslp $o14App | foreach -EA 1 { + GetResult $oslp $osls $_ + Write-Host "$line3" + if (!$All.IsPresent) {Write-Host} + } +} + +if ($NT7) { + vNextDiagRun +} + +ExitScript 0 +:sppmgr: