Notice how the code detects
the number of arguments first, and then handles the special case of the /? command line switch.
Notice how the code exits with an error level of 1, so you can trap the help request in a batch file if
desired.
Of course, you also need to handle the case where someone provides a single input, but it isn??™t
the /? command line switch. The code displays a special error message along with the same help
that you would normally display for the /? command line switch. Notice that in this case the script
exits with an error level of 2. Using a different error level lets you trap this particular problem in a
batch file.
At this point, the code begins looking at the input. The input must provide two arguments to
map a network drive to a local drive letter. Consequently, when the script detects two input arguments,
it places them in the appropriate variables and attempts to map the network drive. You
might wonder why the script doesn??™t perform all kinds of odd error checking on the input arguments.
The try...catch statement is the secret in this case. If the user provides incorrect input, the
oNetwork.MapNetworkDrive(DriveLtr, UNCName) call fails and the catch part of the statement
traps the error.
Pages:
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478