请问,有没有高手用程序搞过磁盘配额管理....首先要在系统上创建一个系统用户,然后为其指定相关的磁盘配额...有没有高手会啊

解决方案 »

  1.   

    http://singlepine.cnblogs.com/articles/303870.html用api函数NetUserAdd
    1.引用
    using System.Runtime.InteropServices;
    2.定义api
    [DllImport("Netapi32.dll")] 
    public static extern  int NetUserAdd([MarshalAs(UnmanagedType.LPWStr)] string servername, int level, ref USER_INFO_1 buf, int parm_err);

    [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)] 
    public struct USER_INFO_1 

    public string usri1_name;  
    public string usri1_password;  
    public int usri1_password_age;  
    public int usri1_priv;  
    public string usri1_home_dir;  
    public string comment;  
    public int usri1_flags;  
    public string usri1_script_path; 
    }  
    3.新增
    private void Button1_Click(object sender, System.EventArgs e)
    {
    USER_INFO_1 NewUser = new USER_INFO_1(); // Create an new instance of the USER_INFO_1 struct 
     
    NewUser.usri1_name = "UserTestOne"; // Allocates the username 
    NewUser.usri1_password = "password"; // allocates the password 
    NewUser.usri1_priv = 1; // Sets the account type to USER_PRIV_USER 
    NewUser.usri1_home_dir = null; // We didn't supply a Home Directory 
    NewUser.comment = "My First User Made through C#"; // Comment on the User 
    NewUser.usri1_script_path = null; // We didn't supply a Logon Script Path 
     
    if(NetUserAdd(null ,1 ,ref NewUser, 0)!=0) // If the call fails we get a non-zero value 

    MessageBox.Show("Error Adding User","Error",MessageBoxButtons.OK,MessageBoxIcon.Error); 

    }
      

  2.   

    磁盘配额的wmi版本(C#)usingSystem;usingSystem.Management; namespaceDiskQuota{    ///<summary>    ///Class1的摘要说明。    ///</summary>    classClass1    {        ///<summary>        ///应用程序的主入口点。        ///</summary>        [STAThread]        staticvoidMain(string[]args)        {             try             {                  ManagementClassc=newManagementClass("Win32_DiskQuota");                  ManagementObjectquota=c.CreateInstance();                  quota["Limit"]=400000000;                  quota["WarningLimit"]=200000000;                  //Getuseraccountobject                  ManagementObjectaccount=new                      ManagementObject("Win32_Account.Domain=TODAY20040216,Name=ASPNET");                  account.Get();                  //getdiskobject                  ManagementObjectdisk=new                      ManagementObject("Win32_LogicalDisk.DeviceId='F:'");                  disk.Get();                  quota["QuotaVolume"]=disk;                  quota["User"]=account;                  quota.Put();//commit                     ManagementClassc=newManagementClass("Win32_DiskQuota");                  Console.WriteLine(c.SystemProperties);                  foreach(ManagementObjectoinc.GetInstances())                      Console.WriteLine("Next:{0}",o.Path);             }             catch(Exceptione)             {                  Console.WriteLine("error:"+e);             }         }     }}