In the Reader to Reader article "How to Determine the Next Available Drive Letter When Z Is Already Mapped", Simon Zeltser provides a very handy script that determines and maps the next available drive to a network share of your choosing. Because the underlying engine is so useful, I incorporated its functionality in an HTML Application (HTA). By converting Simon's script into an HTA and by taking advantage of some optional arguments of the MapNetworkDrive method of the Windows Script Host's (WSH's) WshNetwork object, I was able to create a more flexible tool.
In his script, Simon used the MapNetworkDrive method of Windows Script Host's (WSH's) WshNetwork object to map a drive to a network share. When he called the MapNetworkDrive method, he used the method's two required arguments, which are the drive letter and the network share's path. The MapNetworkDrive method also has three optional arguments. One optional argument lets you specify whether you want to make the mapping persistent by storing it in the current user's profile. The other two optional arguments let you specify a user ID and password if you want to map a drive under alternate credentials.
For example, suppose you want to use alternate credentials to map the B drive to a shared folder named Tools on the UtilServer server and you want the mapping to persist. You could use code such as
drive.MapNetworkDrive B:, _
\\UtilServer\tools, True _
In this code, the True argument specifies that you want a persistent mapping, DomainName\ImaUser represents the alternate user ID, and MyP@$$w0rd is the password for that user.
After adapting Simon's code so I could create persistent mappings and use alternative credentials when needed, I incorporated it into the HTA. (The rest of Simon's code is virtually untouched, except for some error-checking code that I added.) You can download this HTA by clicking the Download the Code Here button at the top of the page. You don't need to customize the HTA at all before using it.
As Figure 1 shows, the HTA's GUI is straightforward and easy to use. If you want to use the credentials with which you logged on to create a nonpersistent mapping, you just enter the path to the network share in the format \\server\share in the top input field and click the MapIt button.
Figure 1: The HTA's GUI
To make the mapping persistent, simply select Yes in the Persistent drop-down box. When you make a mapping persistent, the network share will be mapped when you log on again, providing you have access and network connectivity to that share.
To create a mapping under alternate credentials, you need to enter the user ID and password of the alternate account. You must precede the username with either the domain or the server where the account resides. An example of this would be MyDomain\AltUserID.
As I mentioned previously, I made only a few changes to Simon's original code. Basically all I've done to enhance it is to allow the various MapNetworkDrive method arguments to be supplied through the HTA's GUI, which eliminated the need to hard-code arguments in the script and made for an application that's more flexible. My thanks and acknowledgement to Simon for his very useful code.