zoukankan      html  css  js  c++  java
  • 获取Windows用户所有的账户名

     /// <summary>
            /// 设置用户密码
            /// </summary>
           [DllImport("Netapi32.dll")]
            extern static int NetUserEnum([MarshalAs(UnmanagedType.LPWStr)] string sName,int Level,int filter,out IntPtr bufPtr,int Prefmaxlen, out int Entriesread,out int Totalentries,out int Resume_Handle);
           [DllImport("Netapi32.dll")]
            extern static int NetApiBufferFree(IntPtr Buffer);
            /*
            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
            public struct LOCALGROUP_USERS_INFO_0
            {
                public string GroupName;
            }
             */
            [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
            public struct USER_INFO_1
            {
                public string sName;    //用户名
                public string sPass;    //用户密码
                public int PasswordAge; //密码级别
                public int sPriv;       //帐户类型 1
                public string sHomeDir; //用户主目录 null
                public string sComment; //用户描述
                public int sFlags;      //用户权限
                public string sScriptPath;  //登陆脚本路径 null
            }
            public List<string> UserEnum()
            {
                List<String> listNames = new List<string>();
                int Entriesread;
                int TotalEntries;
                int Resume_Handle;
                IntPtr bufPtr;
                if (NetUserEnum(null, 1, 0, out bufPtr, -1, out Entriesread, out TotalEntries, out Resume_Handle) != 0)
                {
                    throw (new Exception("枚举全部用户失败"));
                }
                if (Entriesread > 0)
                {
                    USER_INFO_1[] UserInfo = new USER_INFO_1[Entriesread];
                    IntPtr iter = bufPtr;
                    for (int i = 0; i < Entriesread; i++)
                    {
                        UserInfo[i] = (USER_INFO_1)Marshal.PtrToStructure(iter,  typeof(USER_INFO_1));
                        iter = (IntPtr)((int)iter + Marshal.SizeOf(typeof(USER_INFO_1)));
                        listNames.Add(UserInfo[i].sName);
                        
                    }
                }
                NetApiBufferFree(bufPtr);
                return listNames;
            }
  • 相关阅读:
    关于如何触发控件的事件
    MaxScript转换图像格式
    MaxScript装B技巧一则
    MaxScript.Net接收本地端口的消息执行
    MaxScript创建十二面体的代码
    MaxScript中GW使用范例一则
    Max里,Mesh真是高级自由度啊
    显示当前秒数的MaxScript
    Max2010的activex以及.net界面乱码解决方式
    半夜失眠,码点关于技术美术的字
  • 原文地址:https://www.cnblogs.com/EthanSun/p/3184101.html
Copyright © 2011-2022 走看看