If you’ve ever built a computer and purchased a Windows license, you probably don’t want to buy another license for your next one. With the slmgr command, it’s possible to deactivate your old PC and then activate a new one.

Deactivate an Old PC Instead of Buying a New License

Windows licenses are expensive. At $100 to $200, an official product key from Microsoft costs about the same as a 1 TB solid-state drive, 16 GB of RAM, or a motherboard. And it’s not a good idea to buy cheap keys from sketchy websites. So paying for another license when you want to decommission an old computer in favor of a new one isn’t a great option. The good news is, it’s possible to deactivate a PC you no longer intend to use, then transfer that license to a new computer.

The slmgr command makes this reasonably straightforward, but you’ll want to keep in mind a few limitations. This won’t work for OEM keys, which are keys that came with a computer you bought in a store. Manufacturers embed these keys to the hardware on which they originated, and transferring them to new devices won’t work. And while slmgr can deactivate any retail key (a key you purchased separately), it will only activate a key that matches the installed operating system.

Windows 7 and 8 keys will still activate Windows 10, but only through the standard activation process and not through slmgr . If you enter a “Pro” key on a “Home” install, that too will fail with slmgr . To keep things as simple as possible, transfer a Windows 10 Home key to a Windows 10 Home device, and a Windows 10 Pro key to a Windows 10 Pro device. Otherwise, you’ll have to take some extra steps.

How to Deactivate Your Old PC

Before you get started, make sure you have your Windows Key saved somewhere. If you have a product box or digital receipt, grab it from there. Otherwise, there are some ways you can recover the product key from your old PC, including using Nirsoft’s Produkey.

To deactivate your old PC, you’ll need to open an elevated Command Prompt. Having an administrator account isn’t enough. You will need to click the start button and type “cmd” (without quotes) into the search box. Then click on the “Run as administrator” option to the right.

In the command prompt that appears, run the following command and then restart your computer:

slmgr.vbs /upk

If you’re planning on selling the machine or giving it away, you might want to clear the key from the registry as well. It isn’t strictly necessary to deactivate, but it’s a good idea to protect your key.

Type the following into the command prompt:

slmgr.vbs /cpky

If the commands succeed, your old PC will be deactivated. You can still use Windows, but it won’t be treated as a genuine copy of Windows, and certain features won’t work—like personalizing the desktop. You’ll be in the same state as installing Windows without a product key. If you want to activate Windows, you can purchase a new key and enter it, or buy one from the Windows Store.

How to Activate a New PC

To activate using slmgr , open an elevated Command Prompt and run the following command:

slmgr.vbs /ipk #####-#####-#####-#####-#####

Just replace the #####-#####-#####-#####-##### with your key.

If you try to use a key that hasn’t been deactivated from a previous PC yet, it may seem to work initially. But eventually the activation will fail, and you’ll receive “not genuine” and “renew your PC” notifications.

Again, this will only work if the key exactly matches to the OS you’re using. If you have a Windows 10 Pro key, but Windows 10 Home installed, you’ll just run into an error about non-core Windows.

And if you try to use a previous version key, such as Windows 7 or 10, you’ll receive an invalid key error.

The best thing to do in those cases is to open settings, click on the “Activate Windows” option, and then enter your key manually.

Note that if you use a Pro key and to activate an installed copy of Windows 10 Home, using this method will upgrade to Pro automatically.

Keep in mind that you can only use Windows keys with one installation at a time and plan ahead. If you want to keep your old machine as you build new, you’ll need a second Windows license. But if the plan is to decommission, then save some money and transfer your existing license.