Get the product ID of the windows operating system

Please use below script to get the Product ID of the windows operating system,


import os;
import re;
import ctypes;
import time;
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)
command='reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion" /v productid'
with disable_file_system_redirection():
    out=os.popen(command).read();
id= re.findall('[0-9A-Z]+-[0-9A-Z]+-[0-9A-Z]+-[0-9A-Z]+', out)
if id[0]:
    print "Windows product key:",id[0];
else:
    print "Product key not found"


20170127-Get-Product-ID.json (1.32 KB)

The script doesn’t work. It’s returning with the windows install ID and not the the install product key.

Hi @ikondata

Ok. We will analyse the script logic and let you know the update soon.

Thanks,
Kannan

Hi @ikondata

Please refer and check attached script to get product key.We are waiting for your feedback.

Thanks

20170216-GetProductkey.json (2.78 KB)

i run this script and it produces same product key output for all devices, not working. can we fix? what other info you need?

Log Detail

Time Status Additional information
2017/04/21 03:51:35 PM Finished success The Product key is HCVKQ-MHG2J-QMP8W-BLOCKED OUT

this same info comes up on

Hi hytekcomputers,

We are unable to fetch the exact product key of a system, but we have somehow managed to get the “DigitalProductId” along with other software licensing details of the windows.

Please find the script below

``` import os import re; import ctypes;

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"""
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)

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)
print "The Digital Product ID is : " +result[0]
print "                                                                   "
guid=os.popen('cscript C:\Windows\System32\slmgr.vbs /dlv').read();
print(guid)
os.remove("GetProductKey.vbs")
```

Sample Output 01:

Sample Output02:

20170424-View_DigitalProductId_of_a_system.json (2.69 KB)

working nicely. thanks support!