Jump to content
Sign in to follow this  
DarrenWhite99

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

I know this is old, but my issue is more along the lines of is the machine running Enterprise edition or Professional.

I added

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%  Not Contains Enterprise Edition 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

I hope it works the way I think it will and allows me to force upgrade people to Enterprise edition.

Share this post


Link to post
Share on other sites
On 9/3/2019 at 2:11 PM, chris.mathis said:

I added


15,    IF  %shellresult%  Not Contains Enterprise Edition THEN Jump to :InstallLicenseKey.

I hope it works the way I think it will and allows me to force upgrade people to Enterprise edition.

Could you provide an example of the output before a valid key had been applied, and after?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...