‎01-09-2015 11:35 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
{actionpath}activateWindows.vbs "{computer}"
‎11-02-2017 07:34 PM
‎05-03-2016 06:55 PM
‎04-30-2016 02:57 AM
‎04-29-2016 07:04 PM
‎04-29-2016 06:34 PM
‎04-29-2016 06:01 PM
‎02-25-2016 03:19 PM
‎02-16-2016 11:03 PM
Experience Lansweeper with your own data. Sign up now for a 14-day free trial.
Try Now