Recipe 7.16. Limiting a User to a Specified Disk Quota


Problem

You want to configure disk quota limits for a particular user.

Solution

Using a graphical user interface

  1. Open Windows Explorer.

  2. Browse to the drive on which you want to enable quotas, right-click it, and select Properties.

  3. Click the Quota tab.

  4. If quotas are enabled, click the Quota Entries button. If quotas are not enabled, enable them as described in Recipe 7.15.

  5. To configure a new quota entry for a user, select Quota New Quota Entry from the menu.

  6. Use the object picker to locate the target user and click OK. The Add New Quota Entry dialog will open.

  7. If you've configured a default quota, that limit will be selected by default. You can disable disk quota enforcement for this user or set new limit and warning levels. After you are done, click OK.

Using a command-line interface

The following command configures a quota for a particular user:

> fsutil quota modify <Drive> <WarningBytes> <LimitBytes> <Domain\User>

The following example sets a quota for user AMER\rallen with a ~381 MB warning and ~476 MB limit:

> fsutil quota modify d: 400000000 500000000 AMER\rallen

Using VBScript
' This code configures a quota for a particular user. ' ------ SCRIPT CONFIGURATION ------ strComputer = "." strUser = "<User>"             ' e.g. rallen strUserDomain = "<Domain>"     ' e.g. AMER strDrive = "<Drive>"           ' e.g. D: intLimit = 1024 * 1024 * 600   ' = 600 MB intWarning = 1024 * 1024 * 350 ' = 350 MB ' ------ END CONFIGURATION --------- set objWMI = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set objDisk = objWMI.Get("Win32_LogicalDisk.DeviceID='" & strDrive & "'") WScript.Echo "Found disk " & objDisk.Caption set objUser = objWMI.Get("Win32_Account.Domain='" & strUserDomain & _                          "',Name='" & strUser & "'") WScript.Echo "Found user " & objUser.Name set objQuota = objWMI.Get("Win32_DiskQuota.QuotaVolume=" & _       "'Win32_LogicalDisk.Device" & strDrive & """'," & _        "User='Win32_Account.Domain=""" & strUserDomain & _       """,Name=""" & strUser & """'") objQuota.Limit = intLimit objQuota.WarningLimit = intWarning objQuota.Put_ WScript.Echo "Set quota for user " & objUser.Name

Discussion

If you decide that you want to delete a quota entry for a particular user, perhaps because you don't want to limit that user anymore, you have to first reassign ownership of all files owned by the user on the volume. Since quota usage is entirely determined by file ownership, you can't have files on a quota-enabled volume that belong to a user that doesn't have a quota entry. You must take ownership of the files yourself, move the files to another volume, or permanently delete the files before deleting the quota entry.

If you don't want to go to all the trouble of transferring ownership of files, another option would be to simply set the quota for the user really high (like to the overall size of the volume).


See Also

Recipe 7.15 for enabling disk quotas; MS KB 183322, "How to Enable Disk Quotas in Windows 2000," MS KB 307984, "HOW TO: Create Disk Quota Reports in Windows XP," and MS KB 308664, "How To Export and Import Disk Quota Settings to Other Volumes in Windows XP"



Windows XP Cookbook
Windows XP Cookbook (Cookbooks)
ISBN: 0596007256
EAN: 2147483647
Year: 2006
Pages: 408

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