Windows IT Pro is the leading independent community for IT professionals deploying Microsoft Windows server and client applications and technologies.
  
  
  Advanced Search 


May 14, 2009

HTA Automatically Creates Mappings

RSS
Subscribe to Windows IT Pro | See More Systems Administration Articles Here | Reprints | Or get the Monthly Online Pass—only $5.95 a month!

Download the Code Here

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.

End of Article



Reader Comments

You must be a registered user or online subscriber to comment on this article. Please log on before posting a comment. Are you a new visitor? Register now




Top Viewed ArticlesView all articles
Command Prompt Tricks

One reader shares his tip for setting up the command prompt to reflect a remote path. ...

WinInfo Short Takes: Week of November 23, 2009

An often irreverent look at some of the week's other news, including some post-PDC some soul searching, a Google Chrome OS announcement and a Microsoft response, Windows 7 off to a supposedly strong start, the Jonas Brothers and Xbox 360, and so much more ...

2009 Windows IT Pro Editors' Best and Community Choice Awards

Picking a favorite product from an impressive crowd of competitive offerings is never an easy task, and such was the case with our Editors' Best and Community Choice awards this year. ...


Related Articles Creating Context-Sensitive Help Screens for Your HTAs

HTA F/X

Use an HTA as a UI for Your VBScript Scripts

Hooked on HTAs

Scripting Whitepapers From Development to Production: Streamlining SharePoint Deployment with DocAve Deployment Manager

Related Events Deep Dive into Windows Server 2008 R2 presented by John Savill

7 Ways To Get More From Your SharePoint Deployment Now

Configuration Manager SP1 and R2 Overview

Check out our list of Free Email Newsletters!

Scripting eBooks Keeping Your Business Safe from Attack: Encryption and Certificate Services

Best Practices for Managing Linux and UNIX Servers

Building an Effective Reporting System

Related Scripting Resources Introducing Left-Brain.com, the online IT bookstore
Looking for books, CDs, toolkits, eBooks? Prime your mind at Left-Brain.com

Discover Windows IT Pro eLearning Series!
Clear & detailed technical information and helpful how-to's, all in our trademark no-nonsense format


Windows IT Pro Home Register FAQ for Windows WinInfo News
Europe Edition About Us Contact Us/Customer Service Media Kit Affiliates / Licensing  
SQL Server Magazine Office & SharePoint Pro DevProConnections IT Job Hound
Left-Brain.com Technology Resource Directory asp.netPRO ITTV Windows SuperSite 
 
 Windows IT Pro is a Division of Penton Media Inc.
 © 2009 Penton Media, Inc. Terms of Use | Privacy Statement