Advertisement

How to view your product key in Windows 10, Windows 8 and Windows 7

If you lost or forgot where you had stored your Windows product key, I have a solution for you. Today we will see how a simple VBS script can be used to show us the product key of an installed copy of Windows 10, Windows 8 or Windows 7. It is a simple solution to extract your product key from the OS installed on your PC without using any third party software. Here we go.

Advertisеment


Actually, earlier I posted a similar solution which used PowerShell. but many users complained that it fails for them. PowerShell might require additional user skills and extra tweaks to run unsigned cmdlets.

Compared to PowerShell, this VBScript solution is almost perfect. All you need to do is to just click the file. To view your Windows 10 product key

  1. Open Notepad.
  2. Copy and paste the following text into the Notepad window
    Option Explicit  
     
    Dim objshell,path,DigitalID, Result  
    Set objshell = CreateObject("WScript.Shell") 
    'Set registry key path 
    Path = "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\" 
    'Registry key value 
    DigitalID = objshell.RegRead(Path & "DigitalProductId") 
    Dim ProductName,ProductID,ProductKey,ProductData 
    'Get ProductName, ProductID, ProductKey 
    ProductName = "Product Name: " & objshell.RegRead(Path & "ProductName") 
    ProductID = "Product ID: " & objshell.RegRead(Path & "ProductID") 
    ProductKey = "Installed Key: " & ConvertToKey(DigitalID)  
    ProductData = ProductName  & vbNewLine & ProductID  & vbNewLine & ProductKey 
    'Show messbox if save to a file  
    If vbYes = MsgBox(ProductData  & vblf & vblf & "Save to a file?", vbYesNo + vbQuestion, "BackUp Windows Key Information") then 
       Save ProductData  
    End If 
     
     
     
    'Convert binary to chars 
    Function ConvertToKey(Key) 
        Const KeyOffset = 52 
        Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert 
        'Check if OS is Windows 8 
        isWin8 = (Key(66) \ 6) And 1 
        Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4) 
        i = 24 
        Maps = "BCDFGHJKMPQRTVWXY2346789" 
        Do 
               Current= 0 
            j = 14 
            Do 
               Current = Current* 256 
               Current = Key(j + KeyOffset) + Current 
               Key(j + KeyOffset) = (Current \ 24) 
               Current=Current Mod 24 
                j = j -1 
            Loop While j >= 0 
            i = i -1 
            KeyOutput = Mid(Maps,Current+ 1, 1) & KeyOutput 
            Last = Current 
        Loop While i >= 0  
         
        If (isWin8 = 1) Then 
            keypart1 = Mid(KeyOutput, 2, Last) 
            insert = "N" 
            KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0) 
            If Last = 0 Then KeyOutput = insert & KeyOutput 
        End If     
         
     
        ConvertToKey = Mid(KeyOutput, 1, 5) & "-" & Mid(KeyOutput, 6, 5) & "-" & Mid(KeyOutput, 11, 5) & "-" & Mid(KeyOutput, 16, 5) & "-" & Mid(KeyOutput, 21, 5) 
        
         
    End Function 
    'Save data to a file 
    Function Save(Data) 
        Dim fso, fName, txt,objshell,UserName 
        Set objshell = CreateObject("wscript.shell") 
        'Get current user name  
        UserName = objshell.ExpandEnvironmentStrings("%UserName%")  
        'Create a text file on desktop  
        fName = "C:\Users\" & UserName & "\Desktop\WindowsKeyInfo.txt" 
        Set fso = CreateObject("Scripting.FileSystemObject") 
        Set txt = fso.CreateTextFile(fName) 
        txt.Writeline Data 
        txt.Close 
    End Function 
    
  3. Save the text above to a file with the ".vbs" extension on the Desktop.
    Bonus tip: To make sure that you saving the file correctly with the ".vbs" extension, you can type its name enclosed in double quotes, for example, "BackupWindowsKey.vbs".
    backup windows product key Windows 10
  4. Now open your BackupWindowsKey.vbs file
  5. Voila, you product key is displayed on the screen!
    show Windows 10 product key

Click here to download the BackupWindowsKey.vbs file

I tested this trick on Windows 7, Windows 8 and Windows 10. It works flawlessly in all mentioned operating systems. Credits: nononsence @ MDL.

Support us

Winaero greatly relies on your support. You can help the site keep bringing you interesting and useful content and software by using these options:

If you like this article, please share it using the buttons below. It won't take a lot from you, but it will help us grow. Thanks for your support!

Advertisеment

Author: Sergey Tkachenko

Sergey Tkachenko is a software developer who started Winaero back in 2011. On this blog, Sergey is writing about everything connected to Microsoft, Windows and popular software. Follow him on Telegram, Twitter, and YouTube.

133 thoughts on “How to view your product key in Windows 10, Windows 8 and Windows 7”

      1. Hi Sergey,
        can this script find product key on external drive with windows 8, and 8.1 64 bit installation connected on windows 10 64 bit laptop?
        produkey program could not find the product key using option “load product keys of external windows installations from all disk plugged to your computer

        can you please twick the script so I can find the product key on my windows 8 laptop that is not working?
        I tried few other programs but no avail.
        by the way great script. I am not programmer.
        thank you.
        Jay

        1. The script works in the loaded OS only.
          I would suggest you the produkey app, but you have already tried it.
          Maybe your laptop has some different kind of license, e,g, the key is flashed into UEFI bios, that’s why apps fail to retrieve it.

    1. I’m in charge of license management at the small IT company I work for. I cannot tell you what a gem you have just provided now that Windows 10 reinstalls are starting to happen thanks to some users. No longer have to worry about productkey64 or anything else. Very nice work, today you win the internet!

    2. hey bro can u provide me a method to change the product ID because my product key and product id is changed due to installation of a third party soft ware but i manage to find my old product ID and Key how can i change the current (interrupt/change by third party software) to my original product key and ID (legal product ID and Key when i purchase my PC comes together)

  1. hi, i have try it, but it display’s me just NNNN’s, i have try the script and the download, well i really like your job, and i think my computer is a special case xD. THANKS!!!

  2. Doesn’t work for me. Win 8.1 64.

    Product Name: Windows 8.1 Enterprise
    Product ID: 00261-80243-63017-AA195
    Installed Key: NBBBB-BBBBB-BBBBB-BBBBB-BBBBB

    1. Change “DigitalID = objshell.RegRead(Path & “DigitalProductId”)” to “DigitalID = objshell.RegRead(Path & “DigitalProductId4″)” for Enterprise

      1. Mateusz Paluszkiewicz, I changed “DigitalProductId” to “DigitalProductId4” on Sergey Tkachenko’s VBScript for my Windows 7 Professional … and I got my Product Key. I could not believe my eyes, but there it was right on front of me, after years of frustration. Thank you. Thank you. Thank you very much.
        You both are stars. May God bless you and expand your territory.
        Вы оба звезды. Да благословит вас Бог и расширит вашу территорию.
        Vy oba zvezdy. Da blagoslovit vas Bog i rasshirit vashu territoriyu.

  3. I tried it on six machines. On four (2-Win 8.1 (a laptop and a desktop), 1-Win 7 (laptop), and 1-Vista(desktop)) it worked correctly. On the other two (1-Win 8.1 and 1-Win 8 — both laptops), I received this error message:

    “Unable to open registry key ‘HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\DigitalProductId’ for reading.”

    The registry entry does exist — viewing with Regedit.

  4. Got error because my username is only part of user account foldername (has .%userdomain% attached),
    used userprofile setting instead of username, should also help people with more than 1 windows e.g.
    c: for win7 and d: for winX. ( input “set u” in dosbox to see userprofile )

    ‘Save data to a file
    Function Save(Data)
    Dim fso, fName, txt,objshell,UserName
    Set objshell = CreateObject(“wscript.shell”)
    ‘Get current user name
    UserName = objshell.ExpandEnvironmentStrings(“%UserProfile%”)
    ‘Create a text file on desktop
    fName = UserName & “\Desktop\WindowsKeyInfo.txt”
    Set fso = CreateObject(“Scripting.FileSystemObject”)
    Set txt = fso.CreateTextFile(fName)
    txt.Writeline Data
    txt.Close
    End Function

  5. I don’t quite understand this part of the script:


    keypart1 = Mid(KeyOutput, 2, Last)
    insert = "N"
    KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
    If Last = 0 Then KeyOutput = insert & KeyOutput

    Could you please describe how it works? How is the ‘N’ placed at the correct place? And if my product key doesn’t have a ‘N’, will it still work correctly?

    Also, I’ve found out by testing that a Windows 10 key also can consist of a ‘5’. Does the script need to be extended for that purpose?

    Thanks,

    1. Perhaps try this on windows 10 as admin:

      wmic path softwarelicensingservice get OA3xOriginalProductKey

      Or run this vbscript:

      Set WshShell = CreateObject(“WScript.Shell”)
      MsgBox 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

      I get different results from this vbscript. But when I run the one in the blog post above, it gives me the same key as “wmic path softwarelicensingservice get OA3xOriginalProductKey”

  6. am getting product key

    Product Name: Windows 8 Pro

    Installed Key: NBBBB-BBBBB-BBBBB-BBBBB-BBBBB

    Pls help me how to get the original product key which havebeen inserted in my laptop

  7. Hey with this script i can read the Key from Win10Pro but the Key is on all Computer i have seen the same Key this detected Key (VK7JG-NPHTM-C97JM-9MPGT-3V66T) is a generic Key and it is useful for install Windows 10 clean but for Activation is this Key not possible.
    I have read an other a different key in my System with “Token Restore” v. 2.2 for Win7 and the same key i have read with ProduKey.exe (2011version) and keyfinder.exe ( from 2009) but i dont have try this Key for Activate while my Win10Pro is 100% activated directly after Upgrade from Win8.1Pro

  8. I found that it worked fine on my Windows 10 desktop. However a simpler way to get the same result is to use Belarc Advisor. This gives all manner of information, including all software codes.

    1. I am not sold 100% on Belarc, it only pulls Operating System and Office Suite Keys 50% of the time.

      I will try this out on Operating Systems and see how it fairs.

      :)

  9. Thanks for sharing. I have a try on a notebook with Windows version Vista Business. It is strange that the key reproduced is a bit different from the one I input on activation (which is printed on the bottom on my mechine).

  10. if u want to check windows 10 home edition key will work or not, just go to notification, then windows update, then activation. type the key shown by your pc, if u got message to activate then that product key will work.
    & Thanks for that code. :)

  11. This could be improved a bit by allowing the user to select where to save the info via:

    http://www.robvanderwoude.com/vbstech_ui_fileopen.php

    As it stands, the script gives me permission errors when trying to save to the folder you specify since C:\Users isn’t always the home directory for a user.

    1. Actually that link has code that only works for WinXP not other versions. The following link should be better:

      http://blogs.technet.com/b/heyscriptingguy/archive/2005/06/17/how-can-i-show-users-a-dialog-box-that-only-lets-them-select-folders.aspx

  12. Hello,
    Here I have the full code to view any windows key also the ones they put in the bios.
    It’s written in Visual Basic 2008, but you maybe can transform it in later versions.
    Here we go:
    Create a form with 2 textboxes called Textbox1 & Textbox2
    One Exitbutton called Button1
    The paste in following code:

    Public Class Form1
    Inherits System.Windows.Forms.Form
    #Region ” Windows Form Designer generated code ”
    #End Region
    Public Function ShowMyKey(ByVal Path As String, ByVal Name As String) As String

    Dim MessageStyle
    Dim A As Object = My.Computer.Registry.GetValue(Path, Name, 0)
    Dim B As String = “”
    Dim C As String = “”
    Dim D As Integer = 52
    Dim E As Integer = 67
    Dim F(24) As String
    Dim G As Integer = 29
    Dim H As Integer = 15
    Dim J(15) As String
    Dim K(30) As String
    Dim L As String = “”

    If A Is Nothing Then Return “No Value”

    Try
    For i As Integer = LBound(A) To UBound(A)
    B = B & ” ” & Hex(A(i))
    Next
    Catch ex As Exception
    MsgBox(ex.Message, MessageStyle.Crytical)

    End Try

    F(0) = “B” : F(1) = “C” : F(2) = “D” : F(3) = “F” : F(4) = “G” : F(5) = “H”
    F(6) = “J” : F(7) = “K” : F(8) = “M” : F(9) = “P” : F(10) = “Q” : F(11) = “R”
    F(12) = “T” : F(13) = “V” : F(14) = “W” : F(15) = “X” : F(16) = “Y”
    F(17) = “2” : F(18) = “3” : F(19) = “4” : F(20) = “6” : F(21) = “7”
    F(22) = “8” : F(23) = “9”

    Try
    For i = D To E
    J(i – D) = A(i)
    C = C & ” ” & Hex(J(i – D))
    Next
    Catch ex As Exception
    MsgBox(ex.Message, MessageStyle.Crytical)
    End Try
    For i As Integer = G – 1 To 0 Step -1
    If ((i + 1) Mod 6) = 0 Then
    K(i) = “-”
    L = L & “-”
    Else
    Dim M As Integer = 0
    For N As Integer = (H – 1) To 0 Step -1
    Dim O As Integer = ((M * 2 ^ 8) Or J(N))
    J(N) = O \ 24
    M = (O Mod 24)
    Next
    K(i) = F(M)
    L = L & F(M)
    End If
    Next
    Return StrReverse(L)

    End Function
    Public Function ShowMyVersion()
    Dim K As String
    K = My.Computer.Registry.GetValue(“HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion”, “ProductName”, Nothing)
    TextBox2.Text = (K)
    End Function
    Function ConvertToKey(ByVal Path As String, ByVal Name As String) As String
    Dim A As Object = My.Computer.Registry.GetValue(Path, Name, 0)
    Const KeyOffset = 52
    Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert
    ‘Check if OS is Windows 8
    isWin8 = (A(66) \ 6) And 1
    A(66) = (A(66) And &HF7) Or ((isWin8 And 2) * 4)
    i = 24
    Maps = “BCDFGHJKMPQRTVWXY2346789”
    Do
    Current = 0
    j = 14
    Do
    Current = Current * 256
    Current = A(j + KeyOffset) + Current
    A(j + KeyOffset) = (Current \ 24)
    Current = Current Mod 24
    j = j – 1
    Loop While j >= 0
    i = i – 1
    KeyOutput = Mid(Maps, Current + 1, 1) & KeyOutput
    Last = Current
    Loop While i >= 0
    keypart1 = Mid(KeyOutput, 2, Last)
    insert = “N”
    KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
    If Last = 0 Then KeyOutput = insert & KeyOutput
    ConvertToKey = Mid(KeyOutput, 1, 5) & “-” & Mid(KeyOutput, 6, 5) & “-” & Mid(KeyOutput, 11, 5) & “-” & Mid(KeyOutput, 16, 5) & “-” & Mid(KeyOutput, 21, 5)

    End Function
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    ShowMyVersion()
    If Strings.Left((TextBox2.Text), 10) = “Windows 10” Then GoTo Volg1
    If Strings.Left((TextBox2.Text), 9) = “Windows 8” Then GoTo Volg1
    If Strings.Left((TextBox2.Text), 11) = “Windows 8.1” Then GoTo Volg1
    TextBox1.Text = ShowMyKey(“HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion”, “DigitalProductID”)
    GoTo Af
    Volg1:
    TextBox1.Text = ConvertToKey(“HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion”, “DigitalProductID”)
    Af:
    Button2.Select()
    If (TextBox1.Text) = “” Then Button2_Click(sender, New System.EventArgs)

    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    On Error GoTo Af
    Dim strComputer As String = “.”
    Dim objWMIService As Object = GetObject(“winmgmts:” _
    & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)
    Dim colBIOS As Object = objWMIService.ExecQuery _
    (“Select * from Win32_BIOS”)
    Dim objBIOS As Object
    Dim i As Integer

    For Each objBIOS In colBIOS
    TextBox2.Text = objBIOS.Data()

    Next
    Af:
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Close()
    End Sub
    End Class

    I hope it works for You.

  13. Sorry, forgot something, You also need a button called Button2, but You can make this one invisible or You can arrange the code so You can elliminate this button.

  14. The key that comes using this method didn’t work for me for windows 8 pro. Microsoft says that the eky I got was a windows 8 home key and not a professional version key. Any workarounds?

  15. It can also be made to work with Windows XP by modifying the script a bit….

    Option Explicit

    Dim objshell,path,DigitalID, Result
    Set objshell = CreateObject(“WScript.Shell”)
    ‘Set registry key path
    Path = “HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\”
    ‘Registry key value
    DigitalID = objshell.RegRead(Path & “DigitalProductId”)
    Dim ProductName,ProductID,ProductKey,ProductData
    ‘Get ProductName, ProductID, ProductKey
    ProductName = “Product Name: ” & objshell.RegRead(Path & “ProductName”)
    ProductID = “Product ID: ” & objshell.RegRead(Path & “ProductID”)
    ProductKey = “Installed Key: ” & ConvertToKey(DigitalID)
    ProductData = ProductName & vbNewLine & ProductID & vbNewLine & ProductKey
    ‘Show messbox if save to a file
    If vbYes = MsgBox(ProductData & vblf & vblf & “Save to a file?”, vbYesNo + vbQuestion, “BackUp Windows Key Information”) then
    Save ProductData
    End If

    ‘Convert binary to chars
    Function ConvertToKey(Key)
    Const KeyOffset = 52
    Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert
    ‘Check if OS is Windows 8
    isWin8 = (Key(66) \ 6) And 1
    Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4)
    i = 24
    Maps = “BCDFGHJKMPQRTVWXY2346789”
    Do
    Current= 0
    j = 14
    Do
    Current = Current* 256
    Current = Key(j + KeyOffset) + Current
    Key(j + KeyOffset) = (Current \ 24)
    Current=Current Mod 24
    j = j -1
    Loop While j >= 0
    i = i -1
    KeyOutput = Mid(Maps,Current+ 1, 1) & KeyOutput
    Last = Current
    Loop While i >= 0
    keypart1 = Mid(KeyOutput, 2, Last)
    insert = “N”
    KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
    If Last = 0 Then KeyOutput = insert & KeyOutput
    ConvertToKey = Mid(KeyOutput, 1, 5) & “-” & Mid(KeyOutput, 6, 5) & “-” & Mid(KeyOutput, 11, 5) & “-” & Mid(KeyOutput, 16, 5) & “-” & Mid(KeyOutput, 21, 5)
    End Function

    ‘Save data to a file
    Function Save(Data)
    Dim fso, fName, txt,objshell,UserDesktop
    Set objshell = CreateObject(“wscript.shell”)
    ‘Get current user name
    UserDesktop = objshell.ExpandEnvironmentStrings(“%USERPROFILE%\Desktop”)
    ‘Create a text file on desktop
    fName = UserDesktop & “\WindowsKeyInfo.txt”
    Set fso = CreateObject(“Scripting.FileSystemObject”)
    Set txt = fso.CreateTextFile(fName)
    txt.Writeline Data
    txt.Close
    End Function

    1. Thanks a lot,

      it also works with Windows 11.

      The original one also works but it get a message when I whant to print the result.

      I am running the French version of Windows and it might be the problem.

      === beguinnig of msg =========
      Script
      C:\Users\doume\Doownloads\BachupWindowsKey.vbs
      Ligne : 62
      Caract. : 5
      erreur : Chemin d’accès introuvable
      Code : 800A004C
      Source : Erreur d’exécution Microsoft VBScript
      === end of msg =========

      I am not fmilair with VB and could not find the problem.

      Thanks.

  16. Wow it worked great. Thank you for providing this method, but I have a problem here. When I check in Setting/Update & security/Activation, it shows my product key : XXXXX-XXXXX-XXXXX-XXXXX-ABCEF (well it’s not my real product key but something like that with the last 5 characters are shown). And when I run your script, it shows me a key THGFE-TFNDH-4HFTD-FHRT6-SHFGD (it’s not my real key too). But my point is do those 2 keys suppose to have the same last 5 characters ? In my case, they are different. Is that normal ? If I reinstall windows 10, still I can use the key your script gave me to reactive windows ?

    1. If you got Win10 as a free upgrade then any key you retrieve will be useless because it is totally generic. That is, all free Win10 Home upgraders have the same key, and similarly free Win10 Pro upgraders have the same key.

      Win10 stores your hardware info on MS’ servers so whenever you want to reinstall just skip the key and it will automatically reactivate after connecting to the net and comparing your current hardware info with the stored value. (You can actually change your hard disk and most other things but if you change your motherboard with another model then the activation will fail.)

  17. Hi all, here is the simplest solution:

    press windows key, type in “product key”, the results will show you option under settings: “change your windows product key”

    Click that option.
    Then scroll down & get your last 5 characters of your key, copy this or write it down.

    then press windows key & type : “regedit”

    registry will open, now press cntrl+f to search registry.

    Type in your 5 keys obtained earlier here, then press find…Then Volia…your key will be displayed on right side of screen. (25 Characters long)

    Thats it…eezi peezi… :-) ;-)

  18. Why does my partial product key (last 5 characters) that is shown under Windows 10 Settings not match at all with what this tool shows me ?

    Also, what is the key that is shown in the registry under “BackupProductKeyDefault” in HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SoftwareProtectionPlatform ?

  19. There seems to be something wrong with the vbs script posted on the winaero site:
    https://winaero.com/blog/how-to-view-your-product-key-in-windows-10-windows-8-and-windows-7/

    I have tried this script on several win7 PCs, and the key it displays does not agree with the key shown by other similar utilities such as WinKeyFinder or MagicJellyBean.

    The following all display the same key:
    http://www.winkeyfinder.com/download/winkeyfinder-download/download-win-keyfinder-2-0-beta-1.php
    https://www.magicaljellybean.com/keyfinder/
    http://www.howtogeek.com/206329/how-to-find-your-lost-windows-or-office-product-keys/

    Either your script has a bug or all these other utilities are wrong. The last one on the list is also a similar vbs script, although shorter than the one on your site.

    1. …also the win7 keys produced by your script are invalid according to the Ultimate PID Checker:
      http://janek2012.eu/ultimate-pid-checker/

      1. Thank you very much.
        It was a bug in the script.
        The missing part was as follows

        If (isWin8 = 1) Then 
                keypart1 = Mid(KeyOutput, 2, Last) 
                insert = "N" 
                KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0) 
                If Last = 0 Then KeyOutput = insert & KeyOutput 
            End If 

        I corrected it, now it works fine.

  20. I remember seeing this same VBS a long time back on another site where the original poster had figured out the decryption algo. Forget which one now… But in any case you should credit the original source you took it from.

    1. OK, do you remember the original author?
      Try to google it. Many web sites keep posting the script without credits. Hard to find the original author.

      Actually, I have this script for ages in my collection of scripts and just do not remember where I grabbed it.
      It was several years ago.
      Just as much as I want to credit original author, I don’t want to credit the WRONG PERSON as author.

  21. I have my user folders on another drive, so the save feature didn’t work at all.

    After a little searching, and banging my head against the keyboard repeatedly (I’ve never touched VBScript before), I was able to merge your script and some code from a forum to 1) remove the user name and profile search entirely, and 2) get the script to save the file to my desktop, even though my user profile is on a secondary physical drive.

    I’m testing on Windows 7, and can’t quickly test it on 8 or 10.

    Here’s the modified script:
    Show/Hide

    1. I noticed some of your fixes were missing, so I added those back in:
      Show/Hide

      1. I think I’ve built in a test for Enterprise, based on the info from Mateusz and some Googling about how to test if a reg entry exists.

        Show/Hide

          1. Tried to clean it up a bit and stick closer to the original style. Updated the check for Enterprise so it makes more sense when simply reading it. I’m only posting that section this time, as nothing else was changed.

            'Registry key value
            DigitalID = objshell.RegRead(Path & "DigitalProductId")
            Dim ProductName, ProductID, ProductKey, ProductData, Enterprise
            'Get ProductName, ProductID, ProductKey, check if Enterprise
            ProductName = "Product Name: " & objshell.RegRead(Path & "ProductName")
            On Error Resume Next
            sValue = objshell.regread(Path & "ProductID4")
            If Err.Number 0 Then
            Err.Clear
            Enterprise = False
            Else
            Err.Clear
            Enterprise = True
            End If
            On Error goto 0
            If Enterprise = True then
            ProductID = "Product ID: " & objshell.RegRead(Path & "ProductID4")
            Else
            ProductID = "Product ID: " & objshell.RegRead(Path & "ProductID")
            End If

  22. Worked perfect. NIRSOFT PRODUKEY failed on this, but your script got a correct key instead of an “invalid” key.
    Was able to run the Windows 10 Pro Upgrade after replacing a hard drive.
    Thank you !!!

  23. Here is a modified version for Visual Basic, all wrapped into 1 function.

    Option Strict On
    Option Explicit On
    Option Infer Off
    Imports Microsoft.Win32
    Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    RichTextBox1.Text = RichTextBox1.Text & GetProductID() & vbCrLf
    End Sub
    Function GetProductID() As String
    Dim regKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)
    Dim rkey As RegistryKey = regKey.OpenSubKey(“SOFTWARE\Microsoft\Windows NT\CurrentVersion\”)
    Dim Key As Byte() = DirectCast(rkey.GetValue(“DigitalProductID”), Byte())
    Dim KeyOffset As Integer = 52
    Dim isWin8 As Byte = CByte((Key(66) \ 6) And 1)
    Dim Maps As String = “BCDFGHJKMPQRTVWXY2346789”
    Dim KeyOutput As String = String.Empty
    Dim Last As Integer
    Dim keypart1 As String
    Dim insert As String
    Key(66) = CByte((Key(66) And &HF7) Or ((isWin8 And 2) * 4))
    Dim i As Integer = 24
    Do
    Dim Current As Integer = 0
    Dim j As Integer = 14
    Do
    Current = Current * 256
    Current = Key(j + KeyOffset) + Current
    Key(j + KeyOffset) = CByte((Current \ 24))
    Current = Current Mod 24
    j = j – 1
    Loop While j >= 0
    i = i – 1
    KeyOutput = Mid(Maps, Current + 1, 1) & KeyOutput
    Last = Current
    Loop While i >= 0
    If (isWin8 = 1) Then
    keypart1 = Mid(KeyOutput, 2, Last)
    insert = “N”
    KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
    If Last = 0 Then KeyOutput = insert & KeyOutput
    End If
    Return Mid(KeyOutput, 1, 5) & “-” & Mid(KeyOutput, 6, 5) & “-” & Mid(KeyOutput, 11, 5) & “-” & Mid(KeyOutput, 16, 5) & “-” & Mid(KeyOutput, 21, 5)
    End Function
    End Class

  24. Would this be able to be adapted for finding the product key for Microsoft Office 2016 in Windows 10? I have a lifetime license but lost the product key, and I’m having serious error messages in Microsoft and would like to reinstall. However, Microsoft is telling me I’d have to rebuy the software… if I could just view my product key that would be amazing.

    Thank you so much for your help, this is an invaluable site!

  25. copy paste and run in PowerShell
    (Get-WmiObject -query ‘select * from SoftwareLicensingService’).OA3xOriginalProductKey

  26. Set WshShell = CreateObject(“WScript.Shell”)
    regKey = “HKLMSOFTWAREMicrosoftWindows NTCurrentVersion”
    DigitalProductId = WshShell.RegRead(regKey & “DigitalProductId”)

    Win8ProductName = “Windows Product Name: ” & WshShell.RegRead(regKey & “ProductName”) & vbNewLine
    Win8ProductID = “Windows Product ID: ” & WshShell.RegRead(regKey & “ProductID”) & vbNewLine
    Win8ProductKey = ConvertToKey(DigitalProductId)
    strProductKey =”Windows 8 Key: ” & Win8ProductKey
    Win8ProductID = Win8ProductName & Win8ProductID & strProductKey

    Function ConvertToKey(regKey)
    Const KeyOffset = 52
    isWin8 = (regKey(66) 6) And 1
    regKey(66) = (regKey(66) And &HF7) Or ((isWin8 And 2) * 4)
    j = 24
    Chars = “BCDFGHJKMPQRTVWXY2346789”
    Do
    Cur = 0
    y = 14
    Do
    Cur = Cur * 256
    Cur = regKey(y + KeyOffset) + Cur
    regKey(y + KeyOffset) = (Cur 24)
    Cur = Cur Mod 24
    y = y -1
    Loop While y >= 0
    j = j -1
    winKeyOutput = Mid(Chars, Cur + 1, 1) & winKeyOutput
    Last = Cur
    Loop While j >= 0
    If (isWin8 = 1) Then
    keypart1 = Mid(winKeyOutput, 2, Last)
    insert = “N”
    winKeyOutput = Replace(winKeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
    If Last = 0 Then winKeyOutput = insert & winKeyOutput
    End If
    a = Mid(winKeyOutput, 1, 5)
    b = Mid(winKeyOutput, 6, 5)
    c = Mid(winKeyOutput, 11, 5)
    d = Mid(winKeyOutput, 16, 5)
    e = Mid(winKeyOutput, 21, 5)
    ConvertToKey = a & “-” & b & “-” & c & “-” & d & “-” & e
    End Function
    set filesys = CreateObject(“Scripting.FileSystemObject”)
    set filetxt = filesys.OpenTextFile(“Key Windows.txt”, 8, True)
    filetxt.WriteLine(Win8ProductName)
    filetxt.WriteLine(Win8ProductKey)
    filetxt.WriteBlankLines 1

  27. Thank you so much, my new notebook came preinstall with not recovery disks just a recovery image. I downloaded the iso file for it, Used the Script file you wrote and it worked perfectly.
    Regards
    Gwen

  28. worked perfectly on my sony laptop…..do you have any way of reading product numbers on a win 7 home premium install disk i used authintic win 7 disk but i found those key numbers on line and now the pro id dont match the prod key.so what i need is the nunbers off the disk

  29. my pc status is
    Product Name: Windows 8.1
    Product ID: 00259-60600-00001-AA474
    Installed Key: 334NH-RXG76-64THK-C7CKG-D3VPT
    and it wouldn’t work.
    please help me.

  30. Nice script, TY. Had an error as the path to my user profile wasn’t the same as my username. Modified the script so that it would go to the user profile desktop even if the path is different of it it’s on a drive other than C by using the %UserProfile% variable instead. Changes below:

    Option Explicit

    Dim objshell,path,DigitalID, Result
    Set objshell = CreateObject(“WScript.Shell”)
    ‘Set registry key path
    Path = “HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\”
    ‘Registry key value
    DigitalID = objshell.RegRead(Path & “DigitalProductId”)
    Dim ProductName,ProductID,ProductKey,ProductData
    ‘Get ProductName, ProductID, ProductKey
    ProductName = “Product Name: ” & objshell.RegRead(Path & “ProductName”)
    ProductID = “Product ID: ” & objshell.RegRead(Path & “ProductID”)
    ProductKey = “Installed Key: ” & ConvertToKey(DigitalID)
    ProductData = ProductName & vbNewLine & ProductID & vbNewLine & ProductKey
    ‘Show messbox if save to a file
    If vbYes = MsgBox(ProductData & vblf & vblf & “Save to a file?”, vbYesNo + vbQuestion, “BackUp Windows Key Information”) then
    Save ProductData
    End If

    ‘Convert binary to chars
    Function ConvertToKey(Key)
    Const KeyOffset = 52
    Dim isWin8, Maps, i, j, Current, KeyOutput, Last, keypart1, insert
    ‘Check if OS is Windows 8
    isWin8 = (Key(66) \ 6) And 1
    Key(66) = (Key(66) And &HF7) Or ((isWin8 And 2) * 4)
    i = 24
    Maps = “BCDFGHJKMPQRTVWXY2346789”
    Do
    Current= 0
    j = 14
    Do
    Current = Current* 256
    Current = Key(j + KeyOffset) + Current
    Key(j + KeyOffset) = (Current \ 24)
    Current=Current Mod 24
    j = j -1
    Loop While j >= 0
    i = i -1
    KeyOutput = Mid(Maps,Current+ 1, 1) & KeyOutput
    Last = Current
    Loop While i >= 0

    If (isWin8 = 1) Then
    keypart1 = Mid(KeyOutput, 2, Last)
    insert = “N”
    KeyOutput = Replace(KeyOutput, keypart1, keypart1 & insert, 2, 1, 0)
    If Last = 0 Then KeyOutput = insert & KeyOutput
    End If

    ConvertToKey = Mid(KeyOutput, 1, 5) & “-” & Mid(KeyOutput, 6, 5) & “-” & Mid(KeyOutput, 11, 5) & “-” & Mid(KeyOutput, 16, 5) & “-” & Mid(KeyOutput, 21, 5)

    End Function
    ‘Save data to a file
    Function Save(Data)
    Dim fso, fName, txt,objshell,UserProfile
    Set objshell = CreateObject(“wscript.shell”)
    ‘Get current user name
    UserProfile = objshell.ExpandEnvironmentStrings(“%UserProfile%”)
    ‘Create a text file on desktop
    fName = UserProfile & “\Desktop\WindowsKeyInfo.txt”
    Set fso = CreateObject(“Scripting.FileSystemObject”)
    Set txt = fso.CreateTextFile(fName)
    txt.Writeline Data
    txt.Close
    End Function

  31. i modfied today the output filenaname with Machine and UserName and new location, near by vbs file. better for inventory :)

    only last Function changed:

    ‘Save data to a file
    Function Save(Data)
    Dim fso, fName, txt,objshell,UserName,ComputerName
    Set objshell = CreateObject(“wscript.shell”)
    ‘Get current user name
    UserName = objshell.ExpandEnvironmentStrings(“%UserName%”)
    ‘Get current machine name
    ComputerName = objshell.ExpandEnvironmentStrings(“%ComputerName%”)
    ‘Create a text file on desktop
    fName = “WindowsKeyInfo_” & ComputerName & “_” & UserName & “.txt”
    Set fso = CreateObject(“Scripting.FileSystemObject”)
    Set txt = fso.CreateTextFile(fName)
    txt.Writeline Data
    txt.Close
    End Function

  32. Wow! Works great and it’s super easy to do. However, it doesn’t match my Windows 7 key I used to activate my Windows 10. Does the key change once you use it?

  33. Thought I was about to go on a murderous rampage after all the solutions found on the first three pages of my Google search amounted to nothing, but you saved me from a life in jail, so thank you for that.

  34. It did not work for me:
    Product Name: Windows 7 Professional
    Product ID: 55041-034-3637376-XXXXX (omitted 5 last digits)
    Installed Key: BBBBB-BBBBB-BBBBB-BBBBB-BBBBB-BBBB
    Save to a file?

    My machine is a Windows 7 Professional Service Pack, the computer was a donation. No sticker on it

    Any help very welcome

  35. When I have the same problem a few years ago, maybe this method was my technical use to get my lost product key on my laptop. Now I know. THanks

  36. Hallo,
    I have to do inventory for like 30 Pcs. Do to the fact, that we don’t have the key for all the computers, I searched for a method to get them. The first softwares I tried just gave me the generic Code “VK7JG-NPHTM-C97JM-9MPGT-3V66T”. To make sure that I really become the right key, I now try the method on a Pc where I know the key first.
    Now the skript worked and I really got a key, but it’s also a generic key “NF6HC-QH89W-F8WYV-WWXV4-WFG6P”.
    Is there another method to find the original key?
    P.S. sorry if my english isn’t the best
    Yours,
    Lukas

  37. Hi, Thanks for your tips, but I tried what you said and found a product key and copy paste it, but it said that your key is wrong and didn’t work. What should I do?

  38. Why does this pull the same key for every computer running Windows 7, no matter the make or model?

      1. They were purchased 5 years apart. One was ordered with Windows 7. Four were Windows 8 downgrades. There’s no possible way they were all activated with the same key.

  39. I tried this on my Win 11 and PRESTO – worked as well as it did on on Win 10’s. I have wondered how to accomplish this but never gave it much time. Thanks !!!

Leave a Reply

Your email address will not be published.

css.php
Using Telegram? Subscribe to the blog channel!
Hello. Add your message here.