# This code activates a Windows Server 2003 system.
# ---------------------------------------------------------------
# Adapted from VBScript code contained in the book:
# "Windows Server Cookbook" by Robbie Allen
# ISBN: 0-596-00633-0
# ---------------------------------------------------------------
use Win32::OLE qw(in);
$Win32::OLE::Warn = 3;
# ------ SCRIPT CONFIGURATION ------
$strComputer = '.';
$boolActivateOnline = 1;
# If this is true, boolActivateOffline should
# be false
$boolActivateOffline = 0;
# If this is true, boolActivateOnline should
# be false
$strOfflineConfirmationCode = '1234-5678';
# if Activating offline, you need
# specify a confirmation code
# ------ END CONFIGURATION ---------
$objWMI = Win32::OLE->GetObject('winmgmts:\\\\' . $strComputer . '\\root\\cimv2');
$colWPA = $objWMI->InstancesOf('Win32_WindowsProductActivation');
foreach my $objWPA (in $colWPA) {
print "Activation Settings:\n";
print ' Activation Required: ' . $objWPA->ActivationRequired, "\n";
print ' Caption: ' . $objWPA->Caption, "\n";
print ' Description: ' . $objWPA->Description, "\n";
print ' Notification On: ' . $objWPA->IsNotificationOn, "\n";
print ' Product ID: ' . $objWPA->ProductID, "\n";
print ' Remaining Eval Period: ' . $objWPA->RemainingEvaluationPeriod, "\n";
print ' Remaining Grace Period: ' . $objWPA->RemainingGracePeriod, "\n";
print ' Server Name: ' . $objWPA->ServerName, "\n";
print ' Setting ID: ' . $objWPA->SettingID, "\n";
print "\n";
if ($objWPA->ActivationRequired == 1) {
if ($boolActivateOnline == 1) {
$intRC = $objWPA->ActivateOnline;
if ($intRC != 0) {
print 'Error activating online: ' . $intRC, "\n";
}
else {
print "Successfully activated online\n";
}
}
if ($boolActivateOffline == 1) {
$intRC = $objWPA->ActivateOffline($strOfflineConfirmationCode);
if ($intRC != 0) {
print 'Error activating offline: ' . $intRC, "\n";
}
else {
print "Successfully activated offline\n";
}
}
}
}
|