Jump to content
Sign in to follow this  

Script to Set a Product Key and Activate Windows

Recommended Posts

This script to will take a product key for a parameter, verify that Windows is not already activated, and then set the product key and trigger activation. It has a little randomness in the sleep delay so that if it is executed on multiple systems it won't trigger activation problems from two systems trying to activate simultaneously.

Right after I posted this, I updated it! It now supports product keys with or without dashes (dashes are required but the script will add them) and flagged many steps that would have stopped the script to "Continue On Failure" so that it will log the step/result it did not complete instead of just terminating the script. It also will attempt the activation step up to 10 times if needed. And if you want to replace a key regardless of the current activation state, set @1ToForce@=1 when scheduling the script.

If you have this script and the Script Notes don't say it was updated in 2018 then you have the old version.


Set Windows Product Key and Activate.zip

  • Like 1

Share this post

Link to post
Share on other sites

I know this post is older and honestly I haven't downloaded the .zip and looked at it yet, but I have a question.


How do you verify that Windows is not already activated?  My team has been trying to figure out a way to search for non-activated machines at our clients but the only thing we could think of was searching for a specific event ID.  However the problem with that is if that event has triggered just once in the past, even if it's currently activated, it shows that PC in the search.


How do we do a more accurate search for non-activated Windows devices?

Share this post

Link to post
Share on other sites

Look at the script. 😀

But the logic I am using (nobody has told me I have it wrong yet) is:

12, :CheckInitialActivationStatus - Label
13,    SHELL:  cscript /nologo "%windir%\system32\slmgr.vbs" /dli
14,    IF  %shellresult%  Contains  License Status: Notification  THEN  Jump to :InstallLicenseKey
15,    IF  %shellresult%  Contains  License Status: Licensed  THEN  Jump to :AlreadyLicensed
16,    LOG:  Exiting due to unrecognized License Status. Results: %shellresult%
17, Exit Script

So basically I am looking for "License Status: Notification" as the indicator that a key is needed. (I found a typo in my script, corrected above. As distributed, it says "Existing due to unrecognized..." haha)

The only way to search agents would be to create a remote monitor that runs "%windir%\system32\slmgr.vbs" /dli and look for monitor results with the Notification License Status, or make a script that runs the command and sets an EDF value that could be referenced in a search.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this