
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-09-2015 11:35 PM - last edited on ‎04-01-2024 04:50 PM by Mercedes_O
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
- Labels:
-
API & Integrations

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-02-2017 07:34 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-03-2016 06:55 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-30-2016 02:57 AM
"\\<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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2016 07:04 PM
'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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2016 06:34 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-29-2016 06:01 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-25-2016 03:19 PM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-16-2016 11:03 PM
