一个使用ASP.NET来操作COM的磁盘配额代码.
2004-06-22 21:12
656 查看
using System;
using DiskQuotaTypeLibrary;
namespace Ex3cut3.Libraries { ///
///
///
public class QuotaClass { private DiskQuotaControlClass _diskQuotaControl;
//This path as to be in this format or
//else is going to give an error of invalid path
private const string FILESHAREVOLUME = @"//server/c$/";
private const int MBTOBYTES = 1048576;
public DiskQuotaControlClass DiskQuotaControl
{
get
{
if(this._diskQuotaControl == null)
{
this._diskQuotaControl = new DiskQuotaControlClass();
//Initializes the control to the specified path
this._diskQuotaControl.Initialize(FILESHAREVOLUME, true);
}
return this._diskQuotaControl;
}
}
public QuotaClass()
{
}
///
/// Adds a user to the quota entries of the volume
///
/// The name of the user to Add
/// The domain that the user uses to logon
/// The quota limit of this user
public void Add(string userName, string userDomain, int quotaLimit)
{
DIDiskQuotaUser dskuser = null;
//In some cases if you use name resolution,
//the application will give an error.
this.DiskQuotaControl.UserNameResolution =
UserNameResolutionConstants.dqResolveNone;
//Here we had the user to the Quotas Entrys of
//the volume, we use user@domain.net the logon name of the user.
//You can use the domain/user or just the user,
//but in like this works faster
dskuser = this.DiskQuotaControl.AddUser(
user.SAMAccountName + "@" + user.Domain);
//here we set the limit of the quota, this is
//prepared to receive MB so i convert it to BYTES
dskuser.QuotaLimit = (int)quotaLimit * MBTOBYTES;
//here is the set of the warning limit
dskuser.QuotaThreshold = (int)(quotaLimit / 1.2) * MBTOBYTES;
dskuser = null;
}
///
/// Removes the user form the Quota Entries List
///
///
public void Remove(string userName)
{
//Here we just use the user, and invoke
//the method DeleteUser from the control
this.DiskQuotaControl.DeleteUser(this.GetUser(userName));
}
///
/// A private function to return the user object
///
/// The user name
/// A DIDiskQuotaUser Object
/// of the specified user
private DIDiskQuotaUser GetUser(string userName)
{
//Invokes the method to find a user in a quota entry list
return this.DiskQuotaControl.FindUser(userName);
}
///
/// Gets the quota of the user
///
/// The user name
/// A formated string of the quota
/// limit of the user
private string GetQuota(string userName)
{
//here we return the text of the quota limit
//0.0 bytes, 0.0 Kb, 0.0 Mb etc
return this.GetUser(userName).QuotaLimitText;
}
///
/// Gets the quota currently used by the user
///
/// The user name
/// A formated string of the quota
/// used by the user
private string GetQuotaUsed(string userName)
{
return this.GetUser(userName).QuotaUsedText;
}
///
/// Change the quota of a specified user
///
/// The user name
/// The new quota limit of the user
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;
}
}
}
说明:1,这个操作COM首先要引用一个COM交互操作RWC,首先要添加引用DiskQuotaTypeLibrary.
2,要在ASP.NET中的顶部加入<%@ Page language="c#" aspcompat="true"%>
3,如果要在ASP.NET中操作COM,要有足够的权限,而ASP.NET这个用户的权限是不够的,所以要在web.config中加入这行,当然你也可以用其它的方式来授予权限.
4,OK,告一段落先.<%@ Page language="c#" aspcompat="true" AutoEventWireup="false" %><%@ Page language="c#" aspcompat="true" AutoEventWireup="false" %><%@ Page language="c#" aspcompat="true" AutoEventWireup="false" %>
using DiskQuotaTypeLibrary;
namespace Ex3cut3.Libraries { ///
///
///
public class QuotaClass { private DiskQuotaControlClass _diskQuotaControl;
//This path as to be in this format or
//else is going to give an error of invalid path
private const string FILESHAREVOLUME = @"//server/c$/";
private const int MBTOBYTES = 1048576;
public DiskQuotaControlClass DiskQuotaControl
{
get
{
if(this._diskQuotaControl == null)
{
this._diskQuotaControl = new DiskQuotaControlClass();
//Initializes the control to the specified path
this._diskQuotaControl.Initialize(FILESHAREVOLUME, true);
}
return this._diskQuotaControl;
}
}
public QuotaClass()
{
}
///
/// Adds a user to the quota entries of the volume
///
/// The name of the user to Add
/// The domain that the user uses to logon
/// The quota limit of this user
public void Add(string userName, string userDomain, int quotaLimit)
{
DIDiskQuotaUser dskuser = null;
//In some cases if you use name resolution,
//the application will give an error.
this.DiskQuotaControl.UserNameResolution =
UserNameResolutionConstants.dqResolveNone;
//Here we had the user to the Quotas Entrys of
//the volume, we use user@domain.net the logon name of the user.
//You can use the domain/user or just the user,
//but in like this works faster
dskuser = this.DiskQuotaControl.AddUser(
user.SAMAccountName + "@" + user.Domain);
//here we set the limit of the quota, this is
//prepared to receive MB so i convert it to BYTES
dskuser.QuotaLimit = (int)quotaLimit * MBTOBYTES;
//here is the set of the warning limit
dskuser.QuotaThreshold = (int)(quotaLimit / 1.2) * MBTOBYTES;
dskuser = null;
}
///
/// Removes the user form the Quota Entries List
///
///
public void Remove(string userName)
{
//Here we just use the user, and invoke
//the method DeleteUser from the control
this.DiskQuotaControl.DeleteUser(this.GetUser(userName));
}
///
/// A private function to return the user object
///
/// The user name
/// A DIDiskQuotaUser Object
/// of the specified user
private DIDiskQuotaUser GetUser(string userName)
{
//Invokes the method to find a user in a quota entry list
return this.DiskQuotaControl.FindUser(userName);
}
///
/// Gets the quota of the user
///
/// The user name
/// A formated string of the quota
/// limit of the user
private string GetQuota(string userName)
{
//here we return the text of the quota limit
//0.0 bytes, 0.0 Kb, 0.0 Mb etc
return this.GetUser(userName).QuotaLimitText;
}
///
/// Gets the quota currently used by the user
///
/// The user name
/// A formated string of the quota
/// used by the user
private string GetQuotaUsed(string userName)
{
return this.GetUser(userName).QuotaUsedText;
}
///
/// Change the quota of a specified user
///
/// The user name
/// The new quota limit of the user
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;
}
}
}
说明:1,这个操作COM首先要引用一个COM交互操作RWC,首先要添加引用DiskQuotaTypeLibrary.
2,要在ASP.NET中的顶部加入<%@ Page language="c#" aspcompat="true"%>
3,如果要在ASP.NET中操作COM,要有足够的权限,而ASP.NET这个用户的权限是不够的,所以要在web.config中加入这行,当然你也可以用其它的方式来授予权限.
4,OK,告一段落先.<%@ Page language="c#" aspcompat="true" AutoEventWireup="false" %><%@ Page language="c#" aspcompat="true" AutoEventWireup="false" %><%@ Page language="c#" aspcompat="true" AutoEventWireup="false" %>
相关文章推荐
- HI,各位,我是mdot
- 如何做:创建自定义帐户来运行 ASP.NET
- Asp.Net安全验证小结
- ASP.NET比ASP好在哪
- Asp.Net安全验证小结
- Asp.Net在SqlServer中的图片存取技术
- Asp.net中使用javascrip的模态窗体的一点体会。
- ASP.NET features we use, ASP.NET experience I have
- ASP在中小企业中具有巨大的潜在市场
- 使用 C# .NET 在 ASP.NET 应用程序中实现基于窗体的身份验证
- Life Cycle Stages of ASP.NET Web Page.
- 出错后导向Error.aspx
- Some Articles Help You To Understand ASP.NET ViewState
- Top Ten Tips for Programming ASP.NET
- ASP.NET与非.NET语言进行交互心得
- 如何用Asp判断你的网站的虚拟物理路径
- URL Rewriting with ASP.NET
- Implement Membership & Roles & Personalization in ASP.NET 1.1
- 任何共享软件作者都能挣到一年10万美金以上的收入,只要他想的话
- 思归大哥推荐:对ASP.NET感兴趣的网友可以去读读下列ASP.NET 产品组成员的blog