Chapter 5. File and Print

Hacks #48-53

File and print is the traditional bread and butter of networking, and while it’s gradually being overtaken by more advanced document-management solutions, not may companies are planning on retiring their file servers soon. Managing shared folders and printers also makes up a major component of an administrator’s daily routine, and a high proportion of calls to the help desk as well. So it’s worth examining some new ways to do old tasks, such as mapping drives or configuring default printers, as well as some ways to perform tasks that are not easy using standard Windows tools, including mapping the structure of a directory or determining who has a certain file open on the network. That’s what this chapter is about—doing old tasks in new ways and making complex tasks simple.

Map Network Drives

This quick way to map a network drive can replace the traditional approach of using batch files.

Using VBScript, you can easily map drive letters to shared folders on your network. This approach allows you to use VBScript to map and unmap network drives—for example, in logon scripts. It also allows you greater flexibility in customizing scripts to perform actions across a network and doesn’t require the net use command to work.

Basically, the script creates the Network scripting object and then uses the MapNetworkDrive method to assign a drive letter to a network share. I’ve included examples of code for both mapping and unmapping network drives.

The Code ...

Get Windows Server Hacks now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.