A Pair of Resource Kit Gems

Add a network printer to a workstation and determine what process is using a file

In this column, I have two handy resource kit utilities to share. The first, Con2prt, lets you add a network printer to a workstation, make a network printer the default printer, or clear all printers from the workstation. To make a network printer named \\server1\hplaser the default printer for the workstation you're sitting at, type

con2prt /cd \\server1\hplaser

To add the printer without making it the default, drop the d from the command string. To clear all printers from the workstation, use the /f switch instead of /cd or /c.

You can use a Telnet session to run Con2prt on a remote workstation. The tool also works in batch files. For example, a batch file that contains the statements

con2prt /f
con2prt /cd \\server1\printer1
con2prt /c \\server1\printer2

will delete all existing printer connections, add Printer1 as the default printer, then add Printer2.

You'll find Con2prt in the Microsoft Windows 2000 Resource Kit and in the Zero Administration Kit (ZAK) for Windows (available at http://www.microsoft.com/windows/zak/getzak.htm). To use the tool, you need only the con2prt.exe file; no complex installation is required.

The second tool, OH (for "open handles"), helps when you try to delete a directory only to have the OS tell you that a file in the directory is "in use by another process." In the past, I've used Sysinternals' great Filemon utility (available at http://www.sysinternals.com) or an old copy of Windows File Manager from Windows NT 3.51 to determine which process was using the file. But I recently discovered a resource kit tool called OH that does the job. (To my embarrassment, OH apparently has been around for quite a while.) OH has many options. I'll give you the short version for finding out what program is preventing you from deleting a file.

Before OH will work, you need to run it once. The first invocation modifies Win2K's kernel a bit, adding 8 bytes of information to each running process. Theoretically, that overhead will slow the system, but I've done before-and-after comparisons on several systems and have found no detectable difference in performance or memory utilization. (The resource kit Help file says that you can undo the kernel change later with a tool called gflags.exe, but I haven't tried it.) The worst part of using OH seems to be that a reboot is required for the kernel behavior modification.

After rebooting, you can tell OH to identify the process that's using any given file by typing the command

oh -t file <filename>

The -t switch tells OH that you want information about a particular type of object—a file, in this case. Filename is the name of the file you're interested in.

If you're unsure of the file's name, OH can still help. You can't use the common wildcards (i.e., ? and *) with OH, but you can type the first few characters of the file's name to have OH list all the files in use whose names begin with those characters. Thus, if you know that the file's name is process1.dat or process2.dat, you can just type

oh -t file process

to see whether a file called process1 or process2 is in use.

If you know only the file's extension, type

oh -t file

to dump the name of every file in use. Then, pipe the output through the Find filter to narrow the list to a particular extension. For example, to find all files in use that have the extension .pl, type

oh -t file | find ".pl"

I'll have more gems in my next column.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.