DriveLtr = WScript.Arguments(0);
UNCName = WScript.Arguments(1);
}
// Tell the user which drive is mapped.
WScript.Echo(???Mapping drive ??? + DriveLtr + ??? to ??? + UNCName);
// Attempt to create the connection.
try
{
// Perform the drive mapping function.
oNetwork.MapNetworkDrive(DriveLtr, UNCName);
}
catch(e)
{
// Display an error when the task fails.
WScript.Echo(???Couldn??™t map the drive!\n??? + e.description);
WScript.Quit(3);
}
The example begins by creating a network object to create the connection. In this case, the code
uses the new ActiveXObject() method. You can also use WScript.CreateObject() to perform
the same task. The method you use depends on personal taste in most cases. This example uses the
ActiveXObject() method for the sake of completeness. If you want to use the other method, you
would replace this line of code with var oNetwork = WScript.CreateObject(???WScript.Network???);.
The next section of code addresses the need to handle the /? command line switch. The help displayed
in this example is decidedly weak. You??™d provide a lot more help in a fully functional production
script. The command and utility examples in this book provide you with a good idea of the kind of
186 CHAPTER 6 WORKING WITH SCRIPTS
information you need to provide to make a script useful for everyone.
Pages:
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477