C#

using System;
using System.Collections.Generic;
using System.Management; namespace ConsoleApp2
{
class Win32DiskQuota
{
private static readonly ManagementClass Win32_DiskQuota = new ManagementClass("Win32_DiskQuota"); internal class DiskQuota
{
private readonly string split_sign_1 = "\",Name=\"";
private readonly string split_sign_2 = "Win32_Account.Domain=\"";
private readonly string split_sign_3 = "Win32_LogicalDisk.DeviceID=\"";
internal long DiskSpaceUsed { get; }
internal long Limit { get; }
internal string QuotaVolume { get; }
internal int Status { get; }
internal string User { get; }
internal long WarningLimit { get; } internal string Username { get; }
internal string Domain { get; }
internal string DeviceID { get; }
internal string Line { get; } internal DiskQuota(PropertyDataCollection oProperties)
{
DiskSpaceUsed = Convert.ToInt64(oProperties["DiskSpaceUsed"].Value);
Limit = Convert.ToInt64(oProperties["Limit"].Value);
QuotaVolume = oProperties["QuotaVolume"].Value.ToString();
Status = Convert.ToInt32(oProperties["Status"].Value);
User = oProperties["User"].Value.ToString();
WarningLimit = Convert.ToInt64(oProperties["WarningLimit"].Value);
{
int i = User.IndexOf(split_sign_1);
if (i >= 0)
{
int pos = i + split_sign_1.Length;
Username = User.Substring(pos, User.Length - pos - 1);
int len1 = split_sign_2.Length;
Domain = User.Substring(len1, i - len1);
}
}
{
int i = QuotaVolume.IndexOf(split_sign_3);
if (i == 0)
{
int len1 = split_sign_3.Length;
DeviceID = QuotaVolume.Substring(len1, QuotaVolume.Length - len1 - 1);
}
}
Line = string.Format("{0} {1}\\{2} {3}/{4}", DeviceID, Domain, Username, DiskSpaceUsed, Limit);
}
}
internal static List<DiskQuota> GetAllUserDiskQuota()
{
List<DiskQuota> ret = new List<DiskQuota>();
ManagementObjectCollection ins = Win32_DiskQuota.GetInstances();
foreach (ManagementObject o in ins)
{
DiskQuota diskQuota = new DiskQuota(o.Properties);
ret.Add(diskQuota);
}
return ret;
} internal static void SetDiskQuota(string DeviceId, string UserName, int LimitGB)
{
ManagementObject oQuota = Win32_DiskQuota.CreateInstance();
if (LimitGB < 0)
{
//oQuota["Status"] = 0;
oQuota["Limit"] = 1 * Math.Pow(1024, 4);//次幂1:K,2:M,3:G,4:T,5:P
oQuota["WarningLimit"] = Convert.ToInt64(10 * Math.Pow(1024, 3));
}
else
{
long limitByte = Convert.ToInt64(LimitGB * Math.Pow(1024, 3));
oQuota["Limit"] = limitByte;
oQuota["WarningLimit"] = limitByte / 2;
}
ManagementObject account = new ManagementObject("Win32_Account.Domain=\"" + Environment.MachineName + "\",Name=\"" + UserName + "\"");
account.Get();
//// get disk object
ManagementObject disk = new ManagementObject("Win32_LogicalDisk.DeviceId=\"" + DeviceId + "\"");
disk.Get();
oQuota["QuotaVolume"] = disk;
oQuota["User"] = account;
oQuota.Put();
}
}
}

磁盘配额,通过ManagementClass("Win32_DiskQuota")的更多相关文章

  1. 磁盘配额-----quota

    为什么要使用磁盘配额:为了限制普通用户使用普通磁盘的空间与创建文件的个数等. 不至于个别人的浪费影响所有人的使用. 需要安装quota的软件包. mount -o usrquota,grpquota ...

  2. <实训|第十三天>linux中ACL权限控制以及磁盘配额,附编译属于自己的linux内核

    [root@localhost~]#序言 首先讲讲昨天关于缩容失败,开不机的解决方法:ACL权限也算是一个很重要的知识点,不难,但是很实用:磁盘配额一般不需要自己弄,但是要懂得原理.剩下的就是编译属于 ...

  3. ★Linux磁盘配额的使用 ★——牛刀小试

    磁盘配额的作用:限制普通用户使用磁盘的空间和创建文件的个数,不至于因为个别人的浪费而影响所有人的使用 需要用户程序quota软件包 #rpm -qa | grep quota  查看quota软件包安 ...

  4. Linux用户磁盘配额

    一:内核中支持QUOTA: [root@localhost /]# grep  CONFIG_QUOTA /boot/config-3.10.0-123.el7.x86_64 CONFIG_QUOTA ...

  5. Win2003 Server磁盘配额揭密之补遗篇

    Win2003 Server磁盘配额揭密之补遗篇 [ 作者:茶乡浪子    转贴自:it168.com    点击数:5011    更新时间:2005-1-17  ]   执行查看用户的磁盘配额信息 ...

  6. Win2003 Server磁盘配额揭密之启用篇

    Win2003 Server磁盘配额揭密之启用篇 [ 作者:茶乡浪子    转贴自:it168.com    点击数:4973    更新时间:2005-1-17  ]   本文要向大家介绍如何利用W ...

  7. xfs文件系统磁盘配额

    引言 这篇文章简单介绍一下xfs文件系统的磁盘配额配置. 文章目录 0×1.开启分区磁盘配额 0×2.使用xfs_quota命令配置磁盘配额 0×1.开启分区磁盘配额 对于ext4文件以前的文件系统, ...

  8. Linux磁盘配额实验

    1.实现磁盘限额的条件 *需要Linux内核支持 *安装quota软件包2.Linux磁盘限额的特点 作用范围:针对指定 文件系统(分区) 限制对象:普通用户帐号.组帐号 限制类型:磁盘容量(默认单位 ...

  9. 磁盘配额quota

    磁盘配额 1 启用磁盘配额 首先创建新的分区 /dev/sd5,并创建文件系统. [root@local ~]# mkfs.ext4 /dev/sda5 由于xfs 不磁盘配额能成功,这里使用ext4 ...

随机推荐

  1. Docker 与 Podman 容器管理的比较

    翻译自 Paul Ferrill 2020年9月1日的文章<Compare Docker vs. Podman for container management> [1] Docker 和 ...

  2. charles 常用功能(七)简易接口压力测试(repeat advance 功能)

    接口请求次数.并发量.请求延迟时间均可配置 1.选中需要进行测试的接口,鼠标右键 选中[repeat advance] 设置迭代数量

  3. PyQt(Python+Qt)学习随笔:QTableWidget表格部件中行高和列宽的计算方式

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 QTableWidget表格部件中行高和列宽的计算在Qt提供的资料中内容介绍比较泛,细节说得不清楚, ...

  4. 第15.21节 PyQt(Python+Qt)入门学习:QListView的作用及属性详解

    老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 一.概述 QListView是从QAbstractItemView 派生的类,实现了QAbstrac ...

  5. DVWA SQL Injection Medium

    Mdeium 基本的步骤及知识点在上节已经提到过这里不再赘述:https://blog.csdn.net/WQ_BCJ/article/details/84554777 1)与low级别不同,本次采用 ...

  6. 剑指offer二刷——数组专题——数组中出现次数超过一半的数字

    题目描述 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字.例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输出2. ...

  7. cookie的理解

    第一:每个特定的域名下最多生成20个cookie IE6或更低版本最多20个cookie IE7和之后的版本最多可以有50个cookie Firefox最多50个cookie chrome和Safar ...

  8. BJOI2017 喷式水战改

    题目链接. Description 维护一个序列,支持操作: 每次在 \(P_i\) 位置后插入一段 \(X_i\) 单位的燃料,这一段有三个模式,对应的能量分别是 \(A_i, B_i, C_i\) ...

  9. 数据结构,哈希表hash设计实验

    数据结构实验,hash表 采用链地址法处理hash冲突 代码全部自己写,转载请留本文连接, 附上代码 #include<stdlib.h> #include<stdio.h> ...

  10. Python Windows开发环境搭建

    一.下载python安装包 python官网地址:https://www.python.org/,下载windows平台包并安装 二.在Windows设置环境变量 计算机右键,选择属性,在高级系统设置 ...