Enable dynamic DNS (Perl)

This code can be found in Chapter 1 of Windows Server 2003 Networking Recipes

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

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

# From the book "Windows Server 2003 Networking Recipes"

# This code enables dynamic DNS registration on each NIC
# installed in the local computer
# ------ SCRIPT CONFIGURATION ------

use Win32::OLE qw(in);

$strComputer = '.';
$boolEnabled = 1;
# ------ END CONFIGURATION ---------

$objWMIService = Win32::OLE->GetObject('winmgmts:' . '{impersonationLevel=impersonate}!\\\\' . $strComputer . '\\root\\cimv2');
$nics = $objWMIService->ExecQuery('SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True');

foreach my $nic (in $nics) {
    $intDynamicRegistration = $nic->SetDynamicDNSRegistration($boolEnabled, $boolEnabled);
    if ($intDynamicRegistration == 0) {
        print "
        Success! Dyamic Registration enabled!\n";
    }
    elsif ($intDynamicRegistration == 1) {
        print "Success! Dynamic Registration enabled! Please reboot.\n";
    }
    else {
        print "Error! Unable to enable Dynamic Registration.\n";
    }
}

This code has been viewed 758 times.

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