Recipe3.11.Making a Disk or Volume Read-Only


Recipe 3.11. Making a Disk or Volume Read-Only

This functionality is new to Windows XP and Windows Server 2003 and is not available on Windows 2000.


Problem

You want to make a disk or volume read-only so that users or programs can't write to it.

Solution

Using a command-line interface

The Joeware (www.joeware.net) tool, writeprot, allows you to make a disk or volume read-only as long as no files are locked on that volume. The following command lists the read/write state of all disks and volumes on a system:

> writeprot /mview

The following command attempts to make the D: drive read-only:

> writeprot /vol d: /ro

The following command makes the D: drive read-write:

> writeprot /vol d: /rw

The following command attempts to make all volumes on the basic disk represented by the D: drive read-only:

> writeprot /vol d: /ro

Using VBScript
' This code makes a volume or disk  read-only (if possible) ' ------ SCRIPT CONFIGURATION ------ strDrive = "<Drive>"  ' e.g., e:     ' This assumes writeprot is in your PATH, if not, fully qualify ' the path to the command (e.g., c:\bin\writeprot.exe) strCommand = "writeprot /vol " & strDrive & " /ro" ' ------ END CONFIGURATION --------- set objWshShell = WScript.CreateObject("WScript.Shell") intRC = objWshShell.Run(strCommand, 0, TRUE) if intRC <> 0 then    WScript.Echo "Error returned from running the command: " & intRC    WScript.Echo "Command attempted: " & strCommand else    WScript.Echo "Command executed successfully." end if

Discussion

Volumes on basic disks and dynamic disks are treated different when it comes to enabling write protection. You can make individual volumes on a dynamic disk read-only, but for basic disks, you have to write protect the entire disk including all volumes. If you attempt to write protect a single volume on a basic disk with multiple volumes using writeprot, an error will be returned. You'd need to run the same command with the -unsafe option to write protect all volumes on the basic disk.

You cannot write protect any volume that has files locked for read or write access. Since files are always opened for reading on the system volume, you will not be able to write protect that volume. See Recipe 4.19 for more information on finding open files.

It was reported by some of the technical reviewers of this book that the third-party drivers for some storage area networks devices (HP MSA-500 and MSA-1000 specifically) do NOT properly support write protection.


See Also

Recipe 4.12 and Recipe 4.18



Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net