Have a few remote machines that did not activate when the upgrading to Win10 Creator’s edition.
Found some py code that can be used to pull the key from the BIOS and would like to see that put to good use changing the Win10 key with slmgr.vbs -ipk xxxx-xxxx-xxxx-xxxx
Py code found at https://github.com/christian-korneck .
I so need to learn python.
melih
July 6, 2017, 10:19pm
2
zabolyx:
Have a few remote machines that did not activate when the upgrading to Win10 Creator’s edition.
Found some py code that can be used to pull the key from the BIOS and would like to see that put to good use changing the Win10 key with slmgr.vbs -ipk xxxx-xxxx-xxxx-xxxx
Py code found at christian-korneck (Christian Korneck) · GitHub .
I so need to learn python.
we can keep writing it for you… no problem…
I know that technically the thing is 90%, neigh, 95% done already. Just need to take the key that is pulled from the script Christian wrote and pass that to the slmgr command as a variable.
Python is on my list of about a dozen languages I want to learn. From picking through example scripts I’ve learned enough to do some basic modifications. I’d love to learn more. Maybe a forum for learning to script in python and use it with Comodo could be useful. Or, maybe I’d be the only person in there.
Thanks guys and gals. You all are doing awesome work making a great product even greater.
EDITED: because it’s been a 12 hr day.
I’ve been tinkering with this.
Here is what I have got going so far. Erroring out when trying to apply the new key (thinking I might need to remove old key “slmgr.vbs -cpky”).
import sys
import ctypes
import ctypes.wintypes
import os
import subprocess
#####################################################
#script to query windows 8.x OEM key from PC firmware
#ACPI -> table MSDM -> raw content -> byte offset 56 to end
#ck, 03-Jan-2014 (christian@korneck.de)
#REPURPOSED BY ZABOLYX
#####################################################
#for ref: common STR to DWORD conversions: ACPI: 1094930505 - FIRM: 1179210317 - RSMB: 1381190978 - FACP: 1178682192 - PCAF: 1346584902 - MSDM: 1297302605 - MDSM 1296323405
def EnumAcpiTables():
#returns a list of the names of the ACPI tables on this system
FirmwareTableProviderSignature=ctypes.wintypes.DWORD(1094930505)
pFirmwareTableBuffer=ctypes.create_string_buffer(0)
BufferSize=ctypes.wintypes.DWORD(0)
#http://msdn.microsoft.com/en-us/library/windows/desktop/ms724259
EnumSystemFirmwareTables=ctypes.WinDLL("Kernel32").EnumSystemFirmwareTables
ret=EnumSystemFirmwareTables(FirmwareTableProviderSignature, pFirmwareTableBuffer, BufferSize)
pFirmwareTableBuffer=None
pFirmwareTableBuffer=ctypes.create_string_buffer(ret)
BufferSize.value=ret
ret2=EnumSystemFirmwareTables(FirmwareTableProviderSignature, pFirmwareTableBuffer, BufferSize)
return [pFirmwareTableBuffer.value[i:i+4] for i in range(0, len(pFirmwareTableBuffer.value), 4)]
def FindAcpiTable(table):
#checks if specific ACPI table exists and returns True/False
tables = EnumAcpiTables()
if table in tables:
return True
else:
return False
def GetAcpiTable(table,TableDwordID):
#returns raw contents of ACPI table
#http://msdn.microsoft.com/en-us/library/windows/desktop/ms724379x
GetSystemFirmwareTable=ctypes.WinDLL("Kernel32").GetSystemFirmwareTable
FirmwareTableProviderSignature=ctypes.wintypes.DWORD(1094930505)
FirmwareTableID=ctypes.wintypes.DWORD(int(TableDwordID))
pFirmwareTableBuffer=ctypes.create_string_buffer(0)
BufferSize=ctypes.wintypes.DWORD(0)
ret = GetSystemFirmwareTable(FirmwareTableProviderSignature, FirmwareTableID, pFirmwareTableBuffer, BufferSize)
pFirmwareTableBuffer=None
pFirmwareTableBuffer=ctypes.create_string_buffer(ret)
BufferSize.value=ret
ret2 = GetSystemFirmwareTable(FirmwareTableProviderSignature, FirmwareTableID, pFirmwareTableBuffer, BufferSize)
return pFirmwareTableBuffer.raw
def GetWindowsKey():
#returns Windows Key as string
table=b"MSDM"
TableDwordID=1296323405
if FindAcpiTable(table)==True:
try:
rawtable = GetAcpiTable(table, TableDwordID)
#http://msdn.microsoft.com/library/windows/hardware/hh673514
#byte offset 36 from beginning = Microsoft 'software licensing data structure' / 36 + 20 bytes offset from beginning = Win Key
return rawtable[56:len(rawtable)].decode("utf-8")
except:
return False
else:
print("[ERR] - ACPI table " + str(table) + " not found on this system")
return False
try:
WindowsKey=GetWindowsKey()
if WindowsKey==False:
print("unexpected error")
sys.exit(1)
else:
#print(str(WindowsKey))
#print ("cscript.exe C:/windows/system32/slmgr.vbs -ipk " + (str(WindowsKey)))
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():
process=subprocess.Popen("cscript.exe C:/windows/system32/slmgr.vbs -ipk " + (str(WindowsKey)))
result=process.communicate()
ret=process.returncode
except:
print("unexpected error")
sys.exit(1)
Here is the error I’m getting. I’m starting some research on that to see if I find anything. Using SLUI it just tells me to contact MS licensing.
I’ve got a modified script that I’m currently testing in our environment. Here is the code. Feel free to point out any stupidity in the code.
import sys
import ctypes
import ctypes.wintypes
import os
import subprocess
#####################################################
#script to query windows 8.x OEM key from PC firmware
#ACPI -> table MSDM -> raw content -> byte offset 56 to end
#ck, 03-Jan-2014 (christian@korneck.de)
#REPURPOSED BY ZABOLYX
#####################################################
#for ref: common STR to DWORD conversions: ACPI: 1094930505 - FIRM: 1179210317 - RSMB: 1381190978 - FACP: 1178682192 - PCAF: 1346584902 - MSDM: 1297302605 - MDSM 1296323405
def EnumAcpiTables():
#returns a list of the names of the ACPI tables on this system
FirmwareTableProviderSignature=ctypes.wintypes.DWORD(1094930505)
pFirmwareTableBuffer=ctypes.create_string_buffer(0)
BufferSize=ctypes.wintypes.DWORD(0)
#http://msdn.microsoft.com/en-us/library/windows/desktop/ms724259
EnumSystemFirmwareTables=ctypes.WinDLL("Kernel32").EnumSystemFirmwareTables
ret=EnumSystemFirmwareTables(FirmwareTableProviderSignature, pFirmwareTableBuffer, BufferSize)
pFirmwareTableBuffer=None
pFirmwareTableBuffer=ctypes.create_string_buffer(ret)
BufferSize.value=ret
ret2=EnumSystemFirmwareTables(FirmwareTableProviderSignature, pFirmwareTableBuffer, BufferSize)
return [pFirmwareTableBuffer.value[i:i+4] for i in range(0, len(pFirmwareTableBuffer.value), 4)]
def FindAcpiTable(table):
#checks if specific ACPI table exists and returns True/False
tables = EnumAcpiTables()
if table in tables:
return True
else:
return False
def GetAcpiTable(table,TableDwordID):
#returns raw contents of ACPI table
#http://msdn.microsoft.com/en-us/library/windows/desktop/ms724379x
GetSystemFirmwareTable=ctypes.WinDLL("Kernel32").GetSystemFirmwareTable
FirmwareTableProviderSignature=ctypes.wintypes.DWORD(1094930505)
FirmwareTableID=ctypes.wintypes.DWORD(int(TableDwordID))
pFirmwareTableBuffer=ctypes.create_string_buffer(0)
BufferSize=ctypes.wintypes.DWORD(0)
ret = GetSystemFirmwareTable(FirmwareTableProviderSignature, FirmwareTableID, pFirmwareTableBuffer, BufferSize)
pFirmwareTableBuffer=None
pFirmwareTableBuffer=ctypes.create_string_buffer(ret)
BufferSize.value=ret
ret2 = GetSystemFirmwareTable(FirmwareTableProviderSignature, FirmwareTableID, pFirmwareTableBuffer, BufferSize)
return pFirmwareTableBuffer.raw
def GetWindowsKey():
#returns Windows Key as string
table=b"MSDM"
TableDwordID=1296323405
if FindAcpiTable(table)==True:
try:
rawtable = GetAcpiTable(table, TableDwordID)
#http://msdn.microsoft.com/library/windows/hardware/hh673514
#byte offset 36 from beginning = Microsoft 'software licensing data structure' / 36 + 20 bytes offset from beginning = Win Key
return rawtable[56:len(rawtable)].decode("utf-8")
except:
return False
else:
print("[ERR] - ACPI table " + str(table) + " not found on this system")
return False
try:
WindowsKey=GetWindowsKey()
if WindowsKey==False:
print("unexpected error")
sys.exit(1)
else:
#print(str(WindowsKey))
#print ("cscript.exe C:/windows/system32/slmgr.vbs -ipk " + (str(WindowsKey)))
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():
# process=subprocess.Popen("cscript.exe C:/windows/system32/slmgr.vbs /upk")
# p.communicate() #now wait
with disable_file_system_redirection():
process=subprocess.Popen("cscript.exe C:/windows/system32/slmgr.vbs /cpky")
p.communicate() #now wait
# with disable_file_system_redirection():
# process=subprocess.Popen("cscript.exe C:/windows/system32/slmgr.vbs /ckms")
# p.communicate() #now wait
# with disable_file_system_redirection():
# process=subprocess.Popen("cscript.exe C:/windows/system32/slmgr.vbs /ckms")
# p.communicate() #now wait
# with disable_file_system_redirection():
# process=subprocess.Popen("cscript.exe C:/windows/system32/slmgr.vbs /skms localhost")
# p.communicate() #now wait
with disable_file_system_redirection():
process=subprocess.Popen("cscript.exe C:/windows/system32/slmgr.vbs -ipk " + (str(WindowsKey)))
result=process.communicate()
ret=process.returncode
except:
print("unexpected error")
sys.exit(1)
Hi @zabolyx
Appreciation on your python script and your interest in Python development.
We have sent you the script, please check your mail and provide your feedback on our script
Thank you
kunavarthini
Hi @zabolyx
We have sent a script to your email account which is registered to the forum. Please check your inbox and let us know your feedback
Thanks
Confirmed working. It looks like it requires the end user to reboot their machine, but I’m getting successful activations. I have a monitor running to check if Windows is activated and then run this as the procedure triggered by the monitor. This is taking care of our updated Windows 8 laptops.
My next goal is to see about repurposing some of the BIOS code to pull the service tag and using that to run a matching batch file from a share to hopefully activate the upgraded Win7 machines. Wish me luck.