您的位置:首页 > 编程语言 > ASP

一个使用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" %>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: