Activate (VBScript)

This code can be found in Chapter 2 of Windows Server Cookbook

Purchase XP Cookbook or Networking Recipes for only $25 plus shipping! While supplies last.

Find out how to download all of the VBScript code from this site.

' This code activates a Windows Server 2003 system.
' ---------------------------------------------------------------
' From the book "Windows Server Cookbook" by Robbie Allen
' ISBN: 0-596-00633-0
' ---------------------------------------------------------------
' ------ SCRIPT CONFIGURATION ------
strComputer = "."

boolActivateOnline = True  ' If this is true, boolActivateOffline should
                           ' be false

boolActivateOffline = False ' If this is true, boolActivateOnline should
                            ' be false
strOfflineConfirmationCode = "1234-5678" ' if Activating offline, you need
                                         ' specify a confirmation code
' ------ END CONFIGURATION ---------
set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
set colWPA = objWMI.InstancesOf("Win32_WindowsProductActivation")
for each objWPA in colWPA
   WScript.Echo "Activation Settings:"
   Wscript.Echo "  Activation Required: " & objWPA.ActivationRequired
   Wscript.Echo "  Caption: " & objWPA.Caption
   Wscript.Echo "  Description: " & objWPA.Description
   Wscript.Echo "  Notification On: " & objWPA.IsNotificationOn
   Wscript.Echo "  Product ID: " & objWPA.ProductID
   Wscript.Echo "  Remaining Eval Period: " & objWPA.RemainingEvaluationPeriod
   Wscript.Echo "  Remaining Grace Period: " & objWPA.RemainingGracePeriod
   Wscript.Echo "  Server Name: " & objWPA.ServerName
   Wscript.Echo "  Setting ID: " & objWPA.SettingID
   WScript.Echo

   if objWPA.ActivationRequired = True then
      if boolActivateOnline = True then
         intRC = objWPA.ActivateOnline
         if intRC <> 0 then
            WScript.Echo "Error activating online: " & intRC
         else
            WScript.Echo "Successfully activated online"
         end if
      end if

      if boolActivateOffline = True then
         intRC = objWPA.ActivateOffline(strOfflineConfirmationCode)
         if intRC <> 0 then
            WScript.Echo "Error activating offline: " & intRC
         else
            WScript.Echo "Successfully activated offline"
         end if
      end if
   end if
next

This code has been viewed 1672 times.

New from the creators of TechTasks.com: StatSheet.com