磁盘配额的wmi版本(C#)
时间:2021-01-03 15:29:59|栏目:.NET代码|点击: 次
using System;
using System.Management;
namespace DiskQuota
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
ManagementClass c = new ManagementClass("Win32_DiskQuota");
ManagementObject quota = c.CreateInstance();
quota["Limit"] = 400000000;
quota["WarningLimit"] = 200000000;
// Get user account object
ManagementObject account = new
ManagementObject("Win32_Account.Domain=TODAY20040216,Name=ASPNET");
account.Get();
// get disk object
ManagementObject disk = new
ManagementObject("Win32_LogicalDisk.DeviceId='F:'");
disk.Get();
quota["QuotaVolume"] = disk;
quota["User"] = account;
quota.Put(); // commit
ManagementClass c = new ManagementClass("Win32_DiskQuota");
Console.WriteLine(c.SystemProperties);
foreach (ManagementObject o in c.GetInstances())
Console.WriteLine("Next : {0}", o.Path);
}
catch(Exception e)
{
Console.WriteLine("error:" + e);
}
}
}
}
using System.Management;
namespace DiskQuota
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
class Class1
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main(string[] args)
{
try
{
ManagementClass c = new ManagementClass("Win32_DiskQuota");
ManagementObject quota = c.CreateInstance();
quota["Limit"] = 400000000;
quota["WarningLimit"] = 200000000;
// Get user account object
ManagementObject account = new
ManagementObject("Win32_Account.Domain=TODAY20040216,Name=ASPNET");
account.Get();
// get disk object
ManagementObject disk = new
ManagementObject("Win32_LogicalDisk.DeviceId='F:'");
disk.Get();
quota["QuotaVolume"] = disk;
quota["User"] = account;
quota.Put(); // commit
ManagementClass c = new ManagementClass("Win32_DiskQuota");
Console.WriteLine(c.SystemProperties);
foreach (ManagementObject o in c.GetInstances())
Console.WriteLine("Next : {0}", o.Path);
}
catch(Exception e)
{
Console.WriteLine("error:" + e);
}
}
}
}
上一篇:vs.net控件updatePanel实现无刷新的方法
栏 目:.NET代码
下一篇:关于visual studio 2012 update 2中的新功能介绍
本文标题:磁盘配额的wmi版本(C#)
本文地址:http://www.codeinn.net/misctech/39845.html