Configure NetBIOS over TCP (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 NetBIOS over TCP/IP
# ------ SCRIPT CONFIGURATION ------

use Win32::OLE qw(in);

$strComputer = '.';

use constant DEFAULT => 0;
use constant ENABLED => 1;
use constant DISABLED => 2;
# ------ 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) {
    $intNetBT = $nic->SetTCPIPNetBIOS(ENABLED);
    if ($intNetBT == 0) {
        print "Success! NetBIOS over TCP/IP enabled!\n";
    }
    elsif ($intNetBT == 1) {
        print "Success! NetBIOS over TCP/IP enabled, please reboot.\n";
    }
    else {
        print "Error! Unable to enable NetBIOS over TCP/IP.\n";
    }
}

This code has been viewed 897 times.

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