windows:get_the_windows_product_key:using_powershell
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
windows:get_the_windows_product_key:using_powershell [2022/06/14 09:28] – peter | windows:get_the_windows_product_key:using_powershell [2022/06/14 09:48] (current) – peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Windows - Get the Windows Product Key - Using Powershell ====== | ====== Windows - Get the Windows Product Key - Using Powershell ====== | ||
- | ===== Find OEM Key ===== | + | ===== RunProdKey.bat |
- | Windows has a couple different places where you can find different product keys such as the OEM key from vendors such as Dell, Lenovo, etc; and the BackupProductKeyDefault in the registry. | + | This runs the powershell script **Get-ProductKey.ps1**. |
- | To find the OEM Key you can find your key using this powershell command. | + | < |
- | + | @ECHO OFF | |
- | < | + | Powershell.exe -executionpolicy remotesigned -File ./ |
- | wmic path SoftwareLicensingService get OA3xOriginalProductKey | + | |
</ | </ | ||
- | or | + | <WRAP info> |
+ | **NOTE: | ||
+ | </ | ||
- | <code powershell> | ||
- | powershell " | ||
- | </ | ||
---- | ---- | ||
- | ===== Find the backup Windows Key in the registry | + | ===== Get-ProductKey.ps1 |
- | To find the backup Windows Key in the registry it is located using the regedit | + | <code vb> |
+ | start-process -FilePath " | ||
+ | $SLS = wmic path SoftwareLicensingService get OA3xOriginalProductKey | ||
+ | $RLS = Get-ItemPropertyValue ' | ||
+ | $SLSKey = $SLS.Split(" | ||
+ | $DPID = Get-ItemPropertyValue ' | ||
+ | $EditionID = Get-ItemPropertyValue ' | ||
- | < | + | function ConvertTo-ProductKey { |
- | HKLM: | + | param ( |
- | </code> | + | [parameter(Mandatory = $True, Position = 0)] |
+ | $Registry, | ||
+ | [parameter()] | ||
+ | [Switch]$x64 | ||
+ | ) | ||
+ | begin { | ||
+ | $map = " | ||
+ | } | ||
+ | process { | ||
+ | $ProductKey = "" | ||
+ | |||
+ | $prodkey = $Registry[0x34 .. 0x42] | ||
+ | |||
+ | for ($i = 24; $i -ge 0; $i--) { | ||
+ | $r = 0 | ||
+ | for ($j = 14; $j -ge 0; $j--) { | ||
+ | $r = ($r * 256) -bxor $prodkey[$j] | ||
+ | $prodkey[$j] = [math]:: | ||
+ | $r = $r % 24 | ||
+ | } | ||
+ | $ProductKey = $map[$r] + $ProductKey | ||
+ | if (($i % 5) -eq 0 -and $i -ne 0) { | ||
+ | $ProductKey = " | ||
+ | } | ||
+ | } | ||
+ | $ProductKey | ||
+ | } | ||
+ | } | ||
- | ---- | + | $x = Get-ItemProperty ' |
+ | key = ConvertTo-ProductKey $x.DigitalProductId | ||
- | ===== Find and save the CD Key ===== | + | $prodKey |
+ | |||
+ | Add-Content .\ProductKey.txt===== Get-ProductKey.ps1 | ||
<code vb> | <code vb> | ||
- | Option Explicit | + | start-process -FilePath |
- | Dim objshell, | + | $SLS = wmic path SoftwareLicensingService get OA3xOriginalProductKey |
- | Set objshell = CreateObject("WScript.Shell") | + | |
- | 'Set registry key path | + | |
- | Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" | + | |
- | 'Registry key value | + | |
- | DigitalID | + | |
- | Dim ProductName,ProductID, | + | |
- | 'Get ProductName, | + | |
- | ProductName = " | + | |
- | ProductID = " | + | |
- | ProductKey = " | + | |
- | ProductData | + | |
- | 'Show messbox if save to a file | + | |
- | If vbYes = MsgBox(ProductData & vblf & vblf & "Save to a file?", | + | |
- | Save ProductData | + | |
- | End If | + | |
- | 'Convert binary to chars | + | |
- | Function ConvertToKey(Key) | + | |
- | Const KeyOffset | + | |
- | Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert | + | |
- | 'Check if OS is Windows | + | |
- | isWin8 = (Key(66) | + | |
- | Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4) | + | |
- | i = 24 | + | |
- | Maps = " | + | |
- | Do | + | |
- | Current= 0 | + | |
- | j = 14 | + | |
- | Do | + | |
- | Current = Current* 256 | + | |
- | Current = Key(j + KeyOffset) + Current | + | |
- | Key(j + KeyOffset) = (Current | + | |
- | Current=Current Mod 24 | + | |
- | j = j -1 | + | |
- | Loop While j >= 0 | + | |
- | i = i -1 | + | |
- | KeyOutput = Mid(Maps, | + | |
- | Last = Current | + | |
- | Loop While i >= 0 | + | |
- | If (isWin8 | + | function ConvertTo-ProductKey { |
- | keypart1 = Mid(KeyOutput, 2, Last) | + | param |
- | insert | + | [parameter(Mandatory |
- | KeyOutput | + | |
- | If Last = 0 Then KeyOutput | + | [parameter()] |
- | End If | + | |
- | ConvertToKey | + | ) |
- | End Function | + | begin { |
- | 'Save data to a file | + | $map |
- | Function Save(Data) | + | } |
- | Dim fso, fName, txt, | + | process { |
- | Set objshell = CreateObject(" | + | $ProductKey = "" |
- | 'Get current user name | + | |
- | UserName | + | $prodkey |
- | 'Create a text file on desktop | + | |
- | fName = "C:\Users\" & UserName & "\Desktop\WindowsKeyInfo.txt" | + | for ($i = 24; $i -ge 0; $i--) { |
- | Set fso = CreateObject("Scripting.FileSystemObject") | + | |
- | Set txt = fso.CreateTextFile(fName) | + | for ($j = 14; $j -ge 0; $j--) { |
- | txt.Writeline Data | + | |
- | txt.Close | + | $prodkey[$j] = [math]:: |
- | End Function | + | $r = $r % 24 |
+ | } | ||
+ | $ProductKey = $map[$r] + $ProductKey | ||
+ | if (($i % 5) -eq 0 -and $i -ne 0) { | ||
+ | $ProductKey = " | ||
+ | } | ||
+ | } | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | | ||
+ | $key = ConvertTo-ProductKey $x.DigitalProductId | ||
+ | |||
+ | | ||
+ | |||
+ | | ||
</ | </ | ||
+ | ---- | ||
+ | |||
+ | | ||
+ | </ | ||
---- | ---- | ||
===== CDKey.vbs ===== | ===== CDKey.vbs ===== | ||
+ | |||
+ | This script is run from the **Get-ProductKey.ps1** powershell script. | ||
+ | |||
+ | The powershell script finds the keys such as the OEM Key and the registry BackupProductKeyDefault then appends it to the text file. | ||
<code vb> | <code vb> | ||
Line 163: | Line 187: | ||
---- | ---- | ||
- | ===== Get-ProductKey.ps1 ===== | ||
- | |||
- | <code vb> | ||
- | start-process -FilePath " | ||
- | $SLS = wmic path SoftwareLicensingService get OA3xOriginalProductKey | ||
- | $RLS = Get-ItemPropertyValue ' | ||
- | $SLSKey = $SLS.Split(" | ||
- | $DPID = Get-ItemPropertyValue ' | ||
- | $EditionID = Get-ItemPropertyValue ' | ||
- | |||
- | function ConvertTo-ProductKey { | ||
- | param ( | ||
- | [parameter(Mandatory = $True, Position = 0)] | ||
- | $Registry, | ||
- | [parameter()] | ||
- | [Switch]$x64 | ||
- | ) | ||
- | begin { | ||
- | $map = " | ||
- | } | ||
- | process { | ||
- | $ProductKey = "" | ||
- | |||
- | $prodkey = $Registry[0x34 .. 0x42] | ||
- | |||
- | for ($i = 24; $i -ge 0; $i--) { | ||
- | $r = 0 | ||
- | for ($j = 14; $j -ge 0; $j--) { | ||
- | $r = ($r * 256) -bxor $prodkey[$j] | ||
- | $prodkey[$j] = [math]:: | ||
- | $r = $r % 24 | ||
- | } | ||
- | $ProductKey = $map[$r] + $ProductKey | ||
- | if (($i % 5) -eq 0 -and $i -ne 0) { | ||
- | $ProductKey = " | ||
- | } | ||
- | } | ||
- | $ProductKey | ||
- | } | ||
- | } | ||
- | |||
- | $x = Get-ItemProperty ' | ||
- | $key = ConvertTo-ProductKey $x.DigitalProductId | ||
- | |||
- | $prodKey = " | ||
- | |||
- | Add-Content .\ProductKey.txt $prodKey | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | |||
- | ===== RunProdKey.bat ===== | ||
- | |||
- | The powershell script is run from a bat file which sets the Powershell script bypass for running the powershell script. | ||
- | |||
- | <code bat> | ||
- | @ECHO OFF | ||
- | Powershell.exe -executionpolicy remotesigned -File ./ | ||
- | </ | ||
- | |||
- | ---- | ||
===== References ===== | ===== References ===== |
windows/get_the_windows_product_key/using_powershell.1655198933.txt.gz · Last modified: 2022/06/14 09:28 by peter