Configure WINS servers (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 configures two WINS servers
# ------ SCRIPT CONFIGURATION ------

use Win32::OLE qw(in);

$strComputer = '.';
$strWins1 = '192.168.1.151';
$strWins2 = '192.168.1.152';
# --------- 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) {
    $intSetWINS = $nic->SetWINSServer($strWins1, $strWins2);
    if ($intSetWINSServer == 0) {
        print "Success! WINS servers configured.\n";
    }
    elsif ($intSetWINSServer == 1) {
        print "WINS servers configured, please reboot.\n";
    }
    else {
        print "Error!! Unable to configure WINS servers.\n";
    }
}

This code has been viewed 779 times.

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