Subscribe to Windows IT Pro

 

Get Newsletters

  • Get the Latest News
  • Product Updates
  • Helpful Tricks
  • Productivity Tips

Subscribe Now!

May 14, 2009 12:00 AM

HTA Automatically Creates Mappings

Windows IT Pro
InstantDoc ID #101816
Rating: (1)
Downloads
101816.zip

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

Set drive = _
  WScript.CreateObject("WScript.Network")
drive.MapNetworkDrive B:, _
  \\UtilServer\tools, True _
  DomainName\ImaUser, MyP@$$w0rd

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.

Related Content:

ARTICLE TOOLS

Comments
    There are no comments to display. Be the first one!
You must log on before posting a comment.

Are you a new visitor? Register Here

advertisement

advertisement

White Papers

Get your Windows 7 deployment off to the right start by implementing PC lockdown. A locked-down environment is easier and cheaper to support since users are less likely to make unnecessary changes to the core system configuration - read more here!

Essential Guides

Is your iSCSI "lossy"? The reality is that most off-the-shelf Ethernet hardware deployed for iSCSI can lose packets, resulting in slow performance or application downtime. Learn how to assess your current iSCSI infrastructure and engineer an advanced iSCSI SAN infrastructure.

Web Seminars

What's the best way to keep your network safe from malware? In this web seminar, security expert Greg Shields suggests an alternative method to the traditional blacklisting approach that is common with anti-virus and anti-malware solutions.

eLearning Series

We bring the experts direct to you to share their real-world perspective and expertise. During each event, three sessions stream in real time, so you can learn, ask questions, and get solutions.
Upcoming event: Getting the Most with Exchange 2010 with Paul Robichaux

Subscribe to Windows IT Pro!

Windows is a trademark of the Microsoft group of companies. Windows IT Pro is used by Penton Media Inc. under license from owner.