;; 
;;=====================================================================================----- 
;; 
;;FUNCTION       WinActStatus() 
;; 
;;ACTION         Returns the Windows Activation Status  
;; 
;;AUTHOR         Glenn Barnas 
;; 
;;VERSION        1.0  - 2015/09/09 
;; 
;;HISTORY        1.0  - 2015/09/09 - Initial release 
;; 
;;SYNTAX         WinActStatus([fVerbose]) 
;; 
;;                
;;PARAMETERS     fVerbose - OPTIONAL, Bool - If true, returns the text 
;;               status message instead of the status ID. 
;; 
;;REMARKS        Supports MS Vista and higher platforms 
;; 
;;RETURNS        Int: -1 to 5 or String: verbose activation status message 
;; 
;;DEPENDENCIES   WMI, WSH 
;; 
;;TESTED WITH    Vista, Win7, Win8, W2K8, W2K12 
;; 
;;EXAMPLES       ; Test activation status 
;;               If WinActStatus() <> 1 'Windows is not Activated!' EndIf 
;; 
;;               ' report activation status 
;;               'Activation status: ' WinActStatus(1) @CRLF 
; 
Function WinActStatus(OPTIONAL $_fVerbose)
 
  Dim $_Cmd					; WMIC command to execute 
  Dim $_Result					; result  
  Dim $_oExec					; WSH Exec object 
  Dim $_V					; Windows version number 
 
 
  ; get the OS value from the system registry 
  $_V = ReadValue('HKEY_Local_Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CurrentMajorVersionNumber')
  If Not @ERROR
    $_V = $_V + '.' + ReadValue('HKEY_Local_Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CurrentMinorVersionNumber')
  Else
    $_V = ReadValue('HKEY_Local_Machine\SOFTWARE\Microsoft\Windows NT\CurrentVersion', 'CurrentVersion')
  EndIf
 
  $_V = 1.0 * $_V				; convert to Real number 
 
  If $_V < 6.0
    If $_fVerbose
      $WinActStatus = 'Unable to determine activation status, unsupported O/S'
    Else
      $WinActStatus = -1
    Endif
    Exit 87
  EndIf
 
  $_Cmd = 'wmic PATH SoftwareLicensingProduct WHERE "ProductKeyID like ' + "'" + '%%-%%' + "'" + ' AND Description like ' + "'" + %%Windows%% + "'" + '" get LicenseStatus'
 
  ; instantiate WSH, exit with error if unsupported 
  $_oExec = CreateObject("WScript.Shell").Exec($_Cmd)
  If Not VarType($_oExec) = 9
    $WinActStatus = "Unsupported"
    Exit 10
  EndIf
 
  $_Result = Split($_oExec.StdOut.ReadAll, @CRLF)
  If UBound($_Result) > 0
    $_Result = Val($_Result[1])
  Else
    $_Result = -1
  EndIf
 
  If $_fVerbose
    Select
     Case $_Result = 0
      $_Result = 'Unlicensed'
     Case $_Result = 1
      $_Result = 'Activated'
     Case $_Result = 2
      $_Result = 'Activation Required: OOB Grace'
     Case $_Result = 3
      $_Result = 'Activation Required: OOT Grace'
     Case $_Result = 4
      $_Result = 'Activation Required: Non-Genuine Grace'
     Case $_Result = 5
      $_Result = 'Activation Required: '
     Case $_Result = -1
      $_Result = 'Unable to determine activation status!'
     Case 1
      $_Result = 'Invalid Status Value: ' + $_Result
    EndSelect
  EndIf
 
  $WinActStatus = $_Result
 
  Exit 0
 
EndFunction