How Can I Modify a Disk Quota Entry Under Windows 2000?
Hey, Scripting Guy! How can I modify a disk quota entry under Windows 2000?
Hey, CL. We have some good news and some bad news for you. The bad news is that we’re doing one of those good news-bad news things that nobody ever likes. The good news is that you actually can modify a disk quota entry on a Windows 2000 computer. You can’t do this remotely: the script has to run on the same computer as the disk quota entry. But at least it will do what you ask it to.
For example, here’s a script that changes the quota threshold (the point at which a low disk space warning is issued) and the actual disk quota limit. This script changes the quota entry for user kenmyer on drive C of a computer; on Windows 2000 you have to manage quota entries user-by-user, and disk-by-disk. (In other words, no queries that grab all the disk quota entries for all the users on all the disks.)
Here’s the script:
Set colDiskQuotas = CreateObject(“Microsoft.DiskQuota.1”) colDiskQuotas.Initialize “C:\”, True Set objUser = colDiskQuotas.FindUser(“kenmyer”)
objUser.QuotaThreshold = 90000000 objUser.QuotaLimit = 100000000
The script begins by creating an instance of the Microsoft.DiskQuota.1 object. This object is actually part of the so-called Shell Objects for Scripting, which is why the script must run locally: the Shell objects can’t be created on remote computers. Why? That’s like asking why is the grass green or why is the sky is blue: no one knows.
Well, OK, maybe they do know why the grass is green and the sky is blue. Nevertheless, don’t try to create the Microsoft.DiskQuota.1 object on a remote machine; it won’t work.
We then call the Initialize method to bind to the disk quota information for drive C. As you can see, the Initialize method takes two parameters: the drive we want to connect to (C:) and a second parameter that indicates whether we want to open the drive with read-write access or read-only access. We need read-write access in order to modify a quota entry, so we set this second parameter to True.
After we connect to the disk we need to bind to the disk quota entry for kenmyer; that’s what we do here:
Set objUser = colDiskQuotas.FindUser(“kenmyer”)
We then simply specify new values for the QuotaThreshold and QuotaLimit properties (in bytes) and we’re done. We don’t even have to call a Save method of any kind.
In case you’re wondering, there’s actually quite a bit you can do with disk quotas on Windows 2000; the one limitation is that everything you do must take place on the local machine. For more information, you might check out this portion of the Microsoft Windows 2000 Scripting Guide.