/**
 * +----------------------------------------------------------------------------+
 * |                          Jeffrey M. Hunter                                 |
 * |                      jhunter@idevelopment.info                             |
 * |                         www.idevelopment.info                              |
 * |----------------------------------------------------------------------------|
 * |      Copyright (c) 1998-2009 Jeffrey M. Hunter. All rights reserved.       |
 * |----------------------------------------------------------------------------|
 * | FILE       : MapNetworkDrive.js                                            |
 * | CLASS      : Networking                                                    |
 * | PURPOSE    : Demonstrate how to map two different network drives using the |
 * |              WScript.Network object: (1) without name and password and (1) |
 * |              (1) with name and password.                                   |
 * |                                                                            |
 * |              Note that with JScript, you will need to use "\\" for each    |
 * |              "\" character in the PATH.                                    |
 * |                                                                            |
 * | PARAMETERS : None                                                          |
 * | USAGE      : cscript MapNetworkDrive.js //NoLogo                           |
 * | NOTE       : As with any code, ensure to test this script in a development |
 * |              environment before attempting to run it in production.        |
 * +----------------------------------------------------------------------------+
 **/


function main() {

    var objNetwork;

    objNetwork = new ActiveXObject("WScript.Network");

    // Add New Mapped Network Drive Without Username and Password
    WScript.Echo("Connecting to \\\\Cartman\\Share2...");
    objNetwork.MapNetworkDrive("S:", "\\\\Cartman\\Share2");
    WScript.Echo("Connected.\n");
    
    // Remove Newly Created Mapped Network Drive
    WScript.Echo("Disconnecting mapped drive S:");
    objNetwork.RemoveNetworkDrive("S:");
    WScript.Echo("Disconnected.\n");


    // Add new Mapped Network Drive With Username and Password
    WScript.Echo("Connecting to \\\\Cartman\\Protected...");
    objNetwork.MapNetworkDrive("P:", "\\\\Cartman\\Protected", false, "user", "pass");
    WScript.Echo("Connected.\n");

    // Remove Newly Created Mapped Network Drive
    WScript.Echo("Disconnecting mapped drive P:");
    objNetwork.RemoveNetworkDrive("P:");
    WScript.Echo("Disconnected.\n");

}

main();
WScript.Quit(0);
    
