Talk:Enable/disable NetBIOS over TCP/IP

From WPKG | Open Source Software Deployment and Distribution
Jump to: navigation, search

I propose an alternative to setNetBIOSoverTCPIP.vbs, I implement it in Jscript. It support arguments:

cscript ConfigNetBIOSoverTcpip.js /enable
cscript ConfigNetBIOSoverTcpip.js /disable
cscript ConfigNetBIOSoverTcpip.js /default

ConfigNetBIOSoverTcpip.js

// This code sets the NetBIOS over TCP/IP setting
 
// ------ SCRIPT CONFIGURATION ------
var strComputer = "." ;
 
var DEFAULT = 0 ;
var ENABLE = 1 ;
var DISABLE = 2 ;
var ACTION = DEFAULT;
//  ------ END CONFIGURATION ---------

function showUsage () {
    var message = "Usage:\n"
        + "    cscript set-netbios.js option\n"
        + "\n"
        + "    Options:\n"
        + "        /enable   enable NetBIOS over TCP/IP.\n"
        + "        /disable  disable NetBIOS over TCP/IP.\n"
        + "        /default  use default NetBIOS over TCP/IP (default).\n"
        + "        /help|?   display this help.\n";

    alerte(message);
}

function parseArgs (argv) {
    if (argv.Exists("enable")) {
        ACTION = ENABLE;
    } else if (argv.Exists("disable")) {
        ACTION = DISABLE;
    } else if (argv.Exists("default")){
        ACTION = DEFAULT;
    } else if (argv.Exists("help") || (argv.Exists("?"))) {
        showUsage();
        exit(0);
    } else {
        showUsage();
        exit(1);
    }
}

parseArgs(WScript.Arguments.Named);
        
var WMIServiceStr = "winmgmts:{impersonationLevel=impersonate}!\\\\"
    + strComputer + "\\root\\cimv2";
var objWMIService = GetObject(WMIServiceStr) ;
 
var nics_query = "SELECT * FROM Win32_NetworkAdapterConfiguration"
    + " WHERE IPEnabled = true";
var nics = objWMIService.ExecQuery(nics_query);
 
for ( var items=new Enumerator(nics); !items.atEnd(); items.moveNext() ) {
    //intNetBT = nic.SetTCPIPNetBIOS(DISABLED) ;
    var nic=items.item();
    // WScript.Echo("Before Nic NetBIOS: " + item.TcpipNetbiosOptions);
    nic.SetTcpipNetbios(ACTION);
    // WScript.Echo("After Nic NetBIOS: " + item.TcpipNetbiosOptions);
}

Dad 13:38, 12 May 2009 (CEST)