sodcalculator

10 Tech How-To

Find SQL Server Product Key Installed on Computer

Guide 10-32337 · Updated · Step by step

To find the SQL Server product key installed on your computer, you can retrieve it from the registry or use a script, as the key is not displayed in the SQL Server installation center after setup. The most reliable method is to query the registry for the SQL Server instance’s PID (Product ID) and decode it, or use PowerShell with the SQL Server WMI provider to extract the key.

Why You Might Need the SQL Server Product Key

Knowing the product key is essential for reinstallation, moving a license to a new server, or verifying compliance. Microsoft does not provide a built-in GUI to view the key after installation, so administrators often need a manual method. The key is stored in the registry, but it is encrypted and not directly readable. However, the PID (Product ID) is stored in plain text and can be decoded to reveal the product key.

How SQL Server Stores the Product Key

During installation, SQL Server writes the product key to the registry under the instance-specific key. The registry path is typically:

  • HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\<InstanceID>\Setup

For a default instance, the InstanceID is usually MSSQL14.MSSQLSERVER (for SQL Server 2017) or similar, depending on the version. For named instances, the InstanceID includes the instance name, e.g., MSSQL14.MYINSTANCE. The value name is PID, and it contains a 25-character alphanumeric string (e.g., AAAAA-BBBBB-CCCCC-DDDDD-EEEEE). This PID is not the product key itself, but it can be converted to the product key using a known algorithm.

Methods to Extract the Product Key

There are several ways to retrieve the product key, ranging from manual registry inspection to using scripts. Below are the most common methods.

Method 1: Using PowerShell with WMI

This method uses the SQL Server WMI provider to get the PID, then decodes it. It works for SQL Server 2008 through 2019 (and later).

  1. Open PowerShell as Administrator.
  2. Run the following script (replace MSSQLSERVER with your instance name if it’s a named instance):
$instanceName = "MSSQLSERVER"
$wmi = Get-WmiObject -namespace "root\Microsoft\SqlServer\ComputerManagement15" -class "SqlService" | Where-Object {$_.ServiceName -like "MSSQL$" + $instanceName}
$pid = $wmi | Select-Object -ExpandProperty AdvancedProperties | Where-Object {$_.Name -eq "PID"} | Select-Object -ExpandProperty Value
Write-Host "PID: $pid"

This script retrieves the PID, but decoding it to the product key requires a separate function. Many online scripts include a decoding function, but you can also use the next method.

Method 2: Using the registry and a decoding script

You can directly read the PID from the registry and then use a known decoding algorithm (which is based on the product key structure) to convert it to the actual key. A widely used PowerShell script by the community decodes the PID into the product key. Here is a simplified version:

function Get-SQLKey {
    param($instanceName = "MSSQLSERVER")
    $path = "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL"
    $instanceID = (Get-ItemProperty $path).$instanceName
    $setupPath = "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$instanceID\Setup"
    $pid = (Get-ItemProperty $setupPath).PID
    # Decode logic (simplified)
    $chars = $pid.ToCharArray()
    $key = ""
    for ($i = 0; $i -lt $chars.Length; $i++) {
        $key += [char]([int]$chars[$i] - 1)  # Example, not the actual algorithm
    }
    return $key
}

Note: The actual decoding algorithm is more complex; the above is illustrative. Many complete scripts are available online from reputable sources.

Method 3: Third-party tools

There are third-party utilities (e.g., ProduKey by NirSoft) that can scan the registry and display SQL Server product keys. These tools often have a GUI and are easy to use, but they may trigger antivirus warnings because they access registry data. Use them with caution and only from trusted sources.

Common Problems and Misconceptions

One common issue is that the PID in the registry may be blank or missing if the installation was done with a volume license or if the registry key was cleaned. In such cases, you might need to contact Microsoft or your volume licensing service center. Another misconception is that the product key is the same as the PID. They are different – the PID is an encoded version of the key, and decoding is required. Also, for SQL Server Express editions, the product key is often not stored because it’s free, but you may still find a PID.

Safety and Legal Considerations

Retrieving the product key from your own machine is legal and safe. However, be careful not to share your product key publicly. If you are using a volume license, the key may be a MAK (Multiple Activation Key) or KMS (Key Management Service) key, which has different activation rules. Always ensure you are compliant with your licensing agreement. Do not attempt to bypass activation or use keys for unauthorized installations.

Alternatives and When to Use Them

If you cannot retrieve the key, you may not need it. For example, if you are reinstalling the same version on the same machine, you can sometimes use the PID from the registry. If you are moving to a new server, you might need to deactivate the old installation first. For volume licensing, you can often get the key from the Volume Licensing Service Center (VLSC). For retail versions, check your purchase receipt or email confirmation.

Frequently Asked Questions

Can I find my SQL Server product key from the installation media?

No, the installation media does not contain the product key. The key is entered during setup and stored in the registry. If you lost the key, you can retrieve it from the registry as described above.

Does the product key differ between SQL Server editions?

Yes, different editions (Standard, Enterprise, Developer) have different product keys. The PID in the registry corresponds to the edition installed. You cannot use a Standard key for Enterprise, for example.

What if the registry key is missing?

If the PID is missing, the installation may have been corrupted or the key was removed. You can try repairing the installation or contact Microsoft support. For volume licenses, the key is often not stored locally.

Is it legal to use a script to extract the product key?

Yes, it is legal to retrieve the product key from your own system for legitimate purposes like reinstallation. However, using scripts to extract keys from other systems without permission is illegal.

Can I use the product key from an old SQL Server on a newer version?

No, product keys are version-specific. A SQL Server 2016 key will not work for SQL Server 2019. You need a key for the specific version you are installing.

How do I find the product key for SQL Server Express?

SQL Server Express is free and does not require a product key. It is activated automatically. You may still see a PID in the registry, but you don’t need it for installation.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →