首页 > 代码库 > 枚举当前系统用户(使用NetUserEnum API枚举)
枚举当前系统用户(使用NetUserEnum API枚举)
using System.Runtime.InteropServices;
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct USER_INFO_0
{
public string Username;
}
[DllImport("Netapi32.dll")]
extern static int NetUserEnum(
[MarshalAs(UnmanagedType.LPWStr)]
string servername,
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);
private void button1_Click(object sender, EventArgs e)
{
int EntriesRead;
int TotalEntries;
int Resume;
IntPtr bufPtr;
NetUserEnum(null, 0, 2, out bufPtr, -1, out EntriesRead,
out TotalEntries, out Resume);
if (EntriesRead > 0)
{
USER_INFO_0[] Users = new USER_INFO_0[EntriesRead];
IntPtr iter = bufPtr;
for (int i = 0; i < EntriesRead; i++)
{
Users[i] = (USER_INFO_0)Marshal.PtrToStructure(iter,
typeof(USER_INFO_0));
iter = (IntPtr)((int)iter + Marshal.SizeOf(typeof(USER_INFO_0)));
textBox1.AppendText(Users[i].Username + "/r/n");
}
NetApiBufferFree(bufPtr);
}
}
http://blog.csdn.net/zswang/article/details/1576495
枚举当前系统用户(使用NetUserEnum API枚举)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。