欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

磁盘配额的wmi版本(C#)

程序员文章站 2022-06-08 22:22:14
using system;  using system.management;  namespace diskquota&...
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); 
              } 
         } 
     } 
}