zoukankan      html  css  js  c++  java
  • 枚举当前系统用户(使用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 senderEventArgs e)
    {
        int EntriesRead;
        int TotalEntries;
        int Resume;
        IntPtr bufPtr;
     
        NetUserEnum(null02out bufPtr, -1out 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

  • 相关阅读:
    最近学习的 Node.js 之 http
    最近学习的 Node.js 基础:安装、环境配置、forever
    关于MySQL5.7 几天的总结(简单分区 & json类型)
    不会点git真不行啊.
    python爬虫基础_scrapy
    python爬虫基础_webwechat
    python爬虫基础_requests和bs4
    python之django母板页面
    python之django基础
    python网络之web框架
  • 原文地址:https://www.cnblogs.com/findumars/p/6347943.html
Copyright © 2011-2022 走看看