Introduction
I was developing a platform for an ISP, and I needed to create a library to manage the quota entries of the users. We have decided to use the Windows quota management, that is considerably better in Windows 2003. I had lots of problems trying to find something that worked, so I decided to post the library completely done and working, and so, here it is for everyone that needs this. If you have any comments or something to add, or possible bugs, just email me...
Code Listing
using System;
using DiskQuotaTypeLibrary;
namespace Ex3cut3.Libraries
{
public class QuotaClass
{
private DiskQuotaControlClass _diskQuotaControl;
private const string FILESHAREVOLUME = @"\\server\c$\";
private const int MBTOBYTES = 1048576;
public DiskQuotaControlClass DiskQuotaControl
{
get
{
if(this._diskQuotaControl == null)
{
this._diskQuotaControl = new DiskQuotaControlClass();
this._diskQuotaControl.Initialize(FILESHAREVOLUME, true);
}
return this._diskQuotaControl;
}
}
public QuotaClass()
{
}
public void Add(string userName, string userDomain, int quotaLimit)
{
DIDiskQuotaUser dskuser = null;
this.DiskQuotaControl.UserNameResolution =
UserNameResolutionConstants.dqResolveNone;
dskuser = this.DiskQuotaControl.AddUser(
user.SAMAccountName + "@" + user.Domain);
dskuser.QuotaLimit = (int)quotaLimit * MBTOBYTES;
dskuser.QuotaThreshold = (int)(quotaLimit / 1.2) * MBTOBYTES;
dskuser = null;
}
public void Remove(string userName)
{
this.DiskQuotaControl.DeleteUser(this.GetUser(userName));
}
private DIDiskQuotaUser GetUser(string userName)
{
return this.DiskQuotaControl.FindUser(userName);
}
private string GetQuota(string userName)
{
return this.GetUser(userName).QuotaLimitText;
}
private string GetQuotaUsed(string userName)
{
return this.GetUser(userName).QuotaUsedText;
}
private void ChangeQuota(string userName, int quotaLimit)
{
DIDiskQuotaUser dskuser = this.GetUser(userName);
dskuser.QuotaLimit = quotaLimit * Support.Constants.CONVERTBTOMB;
dskuser.QuotaThreshold = (quotaLimit / 1.2)
* Support.Constants.CONVERTBTOMB;
}
}
}
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.