184 CHAPTER 6 WORKING WITH SCRIPTS
Listing 6.3: Mapping a Network Drive with JavaScript
// Define the network object used to map the drive.
var oNetwork = new ActiveXObject(???WScript.Network???);
// Detect a request for command line help.
if (WScript.Arguments.length == 1)
if (WScript.Arguments(0) == ???/????)
{
// Display the help information
WScript.Echo(???Usage: MapNetwork
\n???);
// Exit the script and provide an error level of 1 to
// indicate a help request.
WScript.Quit(1);
}
else
{
// Display an error message.
WScript.Echo(???Input argument is unknown.???);
WScript.Echo(???Usage: MapNetwork \n???);
// Exit the script and provide an error level of 2 to
// indicate a data entry error.
WScript.Quit(2);
}
// Create variables to hold the drive letter and the UNC location.
var DriveLtr;
var UNCName;
// Detect the correct number of input arguments.
if ( WScript.Arguments.length < 2 )
{
// Ask whether the user wants to continue.
WScript.Echo(???No input provided! Provide it interactively? [Y | N]???);
var Answer = WScript.StdIn.ReadLine();
It??™s this second point where many people get into endless discussions about the suitability of one technique
over another.
Pages:
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475