Check Windows license status in detail

Hi all,

Please refer below procedure to check windows license details completely.


import os;
import re;
import ctypes;

class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)

tmp = os.environ['TEMP']
filepath = tmp+'\\'+r'GetProductKey.vbs'

decodekey ="""
Set wshShell = CreateObject("Wscript.Shell")
WScript.Echo ConvertToKey(WshShell.RegRead("HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId"))
Function ConvertToKey(Key)
Const KeyOffset = 52
i = 28
Chars = "BCDFGHJKMPQRTVWXY2346789"
Do
Cur = 0
x = 14
Do
Cur = Cur * 256
Cur = Key(x + KeyOffset) + Cur
Key(x + KeyOffset) = (Cur \ 24) And 255
Cur = Cur Mod 24
x = x -1
Loop While x >= 0
i = i -1
KeyOutput = Mid(Chars, Cur + 1, 1) & KeyOutput
If (((29 - i) Mod 6) = 0) And (i <> -1) Then
i = i -1
KeyOutput = "-" & KeyOutput
End If
Loop While i >= 0
ConvertToKey = KeyOutput
End Function"""

with disable_file_system_redirection():
    with open (filepath,'w+') as obj:
        obj.write(decodekey)
    os.chdir(tmp)
    a=os.getcwd()
    GetKey = os.popen("cscript.exe GetProductKey.vbs").read()
    regex = r"([A-Za-z0-9]{5}-[A-Za-z0-9]{5}-[A-Za-z0-9]{5}-[A-Za-z0-9]{5}-[A-Za-z0-9]{5})"
    result = re.findall(regex,GetKey)
    guid_digital_key=os.popen('cscript C:\Windows\System32\slmgr.vbs /dlv').read();
    os.remove("GetProductKey.vbs")
    guid=os.popen('cscript C:\Windows\System32\slmgr.vbs /dlv').read();
    os_details = os.popen('systeminfo | findstr /B /C:"OS "').read()

if "License Status: Notification" in guid:
    print guid.replace('License Status: Notification','License Status: Windows is not activated');
elif "License Status: Out-Of-Box Grace Period" in guid:
    print guid.replace('License Status: Out-Of-Box Grace Period','License Status: Windows is not activated')
elif "License Status: Out-Of-Tolerance Grace Period" in guid :
    print guid.replace('License Status: Out-Of-Tolerance Grace Period','License Status: Windows is not activated')
elif "License Status: Non-Genuine Grace Period" in guid:
    print guid.replace('License Status: Non-Genuine Grace Period','License Status: Windows is not activated')
elif 'License Status: Extended Grace' in guid:
    print guid.replace('License Status: Extended Grace','License Status: Windows is not activated')
elif 'License Status: Unlicensed' in guid:
    print guid.replace('License Status: Unlicensed','License Status: Windows is not activated')
elif "License Status: Licensed" in guid:
    print guid
else:
    print guid

print "The Digital Product ID is : " +result[0]
print "                                                                                                 "

print "Information on Operating System"
print os_details









Sample output 1

Sample output 2

20170530-Check_Windows_License_Digital_product_id_And_OS_Information.json (4.43 KB)

Hello @mkannan,

Can you make the Licence Status from License Status: Notification to License Status: Windows is not activated.

Thank you,
Alfie

Hi @alfie013

Yes, it is doable . I will let you know with updated script.

Thanks,
Kannan

Hello @mkannan,

Thank you for your effort. Highly appreciated.

Regards,
Alfie

Hi @alfie013

Please refer attached procedure for output change from " License Status: Notification" to “License Status: Windows is not activated.”

20170123-Check-Windows-license-status-in-detail–Update.json (1.13 KB)

No way to get the complete the installation key on the license info? When tested the procedure it only showed a partial key.

Hi @ikondata

Yes, This script will provide partial product key only.

It will help you to identify whether windows is activated or not and more details regarding windows license status

We will prepare script to get complete installation key and let you know when completed.

Thanks,
Kannan

Hello @mkannan,

Thank you for the updates. Will be going to try it and keep you posted with my findings.

Regards,
Alfie

Hello mkannan,

I have tested the script and worked perfectly. Thank you for the changes you made. Highly appreciated.

Regards,
Alfie

The script should be ported to the ITSM and from there provide via UI all information about Windows.

Hi @ikondata

No way to get the complete the installation key on the license info? When tested the procedure it only showed a partial key.

Please refer below procedure to get full product key

https://forum.mspconsortium.com/forum/script-library/8199-get-the-product-id-of-the-windows-operating-system

Thanks,
Kannan

hi
i added

import os
print os.popen(‘systeminfo | findstr /B /C:"OS "’).read()

to include some more information, example:
OS Name: Microsoft Windows 10 Pro OS Version: 10.0.15063 N/A Build 15063 OS Manufacturer: Microsoft Corporation OS Configuration: Member Workstation OS Build Type: Multiprocessor Free

Hi @phcsolutions

hi
i added

Thank you, We will add this information to the published script as well.

Hi @phcsolutions

We have updated the script in the initial post to output all necessary data. Please check sample outputs as well.

Thanks

Thanks.
this is complete Information