WMI列出磁盘配额

usingSystem;usingSystem.Management;namespaceD
强烈推介IDEA2020.2破解激活,IntelliJ IDEA 注册码,2020.2 IDEA 激活码

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);

}

}

}

 

本文来源21aspnet,由架构君转载发布,观点不代表Java架构师必看的立场,转载请标明来源出处:https://javajgs.com/archives/2305

发表评论