cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
keys_it
Engaged Sweeper III

Hello all,

I thought I share a great custom action that uses a Vbscript that I created to aid in our OEM activation process if one of my tech's forget to activate Windows after using MDT to image a machine as we use OEM versions of Windows Pro. We have a mixed Win 7/8.1 environment so this was the need for using PsExec since a Win 8 slmgr.vbs script will not activate a Win 7 machine and vise versa. We utilize "Comments" page to record the OEM product key as part of our SOP when we acquire new computers to make a record of the OEM key and to easily copy and paste if we need to activate after an new image is applied. For OEM computers that shipped with Win 8 please visit this site to find out how to record the OEM key since I know people are going to ask.

This will even work for MAK keys as we use it activate our servers with the correct MAK after deployments.

In short, this script does the following: uninstalls current key, installs new key that you typed in, activates online, and then displays the licensing status for that computer.

You will need the following in your Lansweeper server's action path:
PsExec
activateWindows.vbs (create from the code below)

Here is the code:


'Pass computer name from Lansweeper to script
strComputer = WScript.Arguments(0)

'Instantiate variables
Set objScript = CreateObject("WScript.Shell")
Set objRegExp = CreateObject("Vbscript.RegExp")

' Define Regular expression
objRegExp.Global = True
objRegExp.Pattern = "^[a-z0-9]{5}(-[a-z0-9]{5}){4}$"
objRegExp.IgnoreCase = True

Do
' Input new product key
sKeyLoop = 0
Dim sProductKey
sProductKey = InputBox("Please enter the Product Key for this computer with the -'s: ", "New Product Key", "")
If trim(sProductKey) = "" Then 'If blank
Wscript.Quit
End If
sProductKey = Replace(sProductKey, " ", "")
sProductKey = trim(UCase(sProductKey))

'Tests to see if valid product key format
If objRegExp.Test(sProductKey) Then
'Continues script
Call ActivateWindows()
Else
Wscript.Echo ("Invalid entry.")
sKeyLoop = 0
End If
Loop While sKeyLoop = 0

'Function for activating windows using PsExec and slmgr.vbs
Function ActivateWindows()
sCmdUninstall = "\\<servername>\lansweeper$\PSTools\PsExec.exe \\" & strComputer & " cscript.exe ""C:\windows\system32\slmgr.vbs"" /upk"
sCmdInstall = "\\<servername>\lansweeper$\PSTools\PsExec.exe \\" & strComputer & " cscript.exe ""C:\windows\system32\slmgr.vbs"" /ipk " & sProductKey
sCmdActivate = "\\<servername>\lansweeper$\PSTools\PsExec.exe \\" & strComputer & " cscript.exe ""C:\windows\system32\slmgr.vbs"" /ato"
sCmdViewLicense = "\\<servername>\lansweeper$\PsExec.exe \\" & strComputer & " cscript.exe ""C:\windows\system32\slmgr.vbs"" /dli"

'Run cmds
objScript.Run sCmdUninstall, 0, True
objScript.Run sCmdInstall, 0, True
objScript.Run sCmdActivate, 0, True
objScript.Run ("%comspec% /K " & sCmdViewLicense)
Wscript.Quit
End Function


Here is the action code for the Asset Pages:
Code:


{actionpath}activateWindows.vbs "{computer}"



I hope you enjoy !

Keys_IT

8 REPLIES 8
kevinjt4
Engaged Sweeper
How long does it take for this script to overwrite the current Windows Key? The script no longer errors, so it appears to work. I am able to run it, enter in the new key and click ok and the window closes. But the key never changes to the key I enter.
chris_sterner
Engaged Sweeper II
Thanks for the help! Running PSExec on the Windows 10 unit first fixed my issue. Thanks again!
TheITGuy
Engaged Sweeper III
Make sure that where it says in the script that you posted that you change where it says:
"\\<servername>\lansweeper$\PSTools\PsExec.exe
you change where it says servername to the actual name of the server (the one you correctly blocked out in the image you posted)

also make sure there is a folder called PSTools in that shared folder lansweeper$ and that psexec.exe is also in that folder.

Make that servername change in the 4 spots.

Also make sure that PsExec is in the lansweeper$ folder because that is the way the script calls for it in xCmdViewLicense.

If your still having issues, you might have to run Psexec on the computer your trying to run this as, i had that issue with trying to run the script from a Windows 10 machine but it worked after that.
chris_sterner
Engaged Sweeper II
Sorry for my ignorance on this. Here is the error I am getting "Line 42/ Char 5/ The Network path was not found" and here is the script:


'Pass computer name from Lansweeper to script
strComputer = WScript.Arguments(0)

'Instantiate variables
Set objScript = CreateObject("WScript.Shell")
Set objRegExp = CreateObject("Vbscript.RegExp")

' Define Regular expression
objRegExp.Global = True
objRegExp.Pattern = "^[a-z0-9]{5}(-[a-z0-9]{5}){4}$"
objRegExp.IgnoreCase = True

Do
' Input new product key
sKeyLoop = 0
Dim sProductKey
sProductKey = InputBox("Please enter the Product Key for this computer with the -'s: ", "New Product Key", "")
If trim(sProductKey) = "" Then 'If blank
Wscript.Quit
End If
sProductKey = Replace(sProductKey, " ", "")
sProductKey = trim(UCase(sProductKey))

'Tests to see if valid product key format
If objRegExp.Test(sProductKey) Then
'Continues script
Call ActivateWindows()
Else
Wscript.Echo ("Invalid entry.")
sKeyLoop = 0
End If
Loop While sKeyLoop = 0

'Function for activating windows using PsExec and slmgr.vbs
Function ActivateWindows()
sCmdUninstall = "\\<servername>\lansweeper$\PSTools\PsExec.exe \\" & strComputer & " cscript.exe ""C:\windows\system32\slmgr.vbs"" /upk"
sCmdInstall = "\\<servername>\lansweeper$\PSTools\PsExec.exe \\" & strComputer & " cscript.exe ""C:\windows\system32\slmgr.vbs"" /ipk " & sProductKey
sCmdActivate = "\\<servername>\lansweeper$\PSTools\PsExec.exe \\" & strComputer & " cscript.exe ""C:\windows\system32\slmgr.vbs"" /ato"
sCmdViewLicense = "\\<servername>\lansweeper$\PsExec.exe \\" & strComputer & " cscript.exe ""C:\windows\system32\slmgr.vbs"" /dli"

'Run cmds
objScript.Run sCmdUninstall, 0, True
objScript.Run sCmdInstall, 0, True
objScript.Run sCmdActivate, 0, True
objScript.Run ("%comspec% /K " & sCmdViewLicense)
Wscript.Quit
End Function
TheITGuy
Engaged Sweeper III
Don't use quotes. And use the dashes between the numbers. They just abbreviated it by saying -s. Remove the -s from the key.
chris_sterner
Engaged Sweeper II
Dumb question but I am not much of a script guy. I get the pop up asking for the Key and I enter it but it says invalid entry. We are using MAK keys. I am confused about the "Please enter the product Key with the -s:". Does that mean my entry should be "-s:XXXXX-XXXXX-XXXXX-XXXXX" without the quotes? I tried it all different ways, but can't seem to get it to work. Oh, and this is for Windows 7 Enterprise.
TheITGuy
Engaged Sweeper III
This also worked for me on Windows 10!
TheITGuy
Engaged Sweeper III
Dude, sweet script! Almost 5k views and only 1 like? (now 2) C'mon people!!! 😉