怎么样用vb编写代码来获得win2000系统的所有用户,添加和删除用户.我尝试过使用api函数getusername,但它只能获得系统登陆用户名,无法获得所有的用户名.

解决方案 »

  1.   

    在DOS下输入net user
    可以得到系统的所有用户
      

  2.   

    赞成,这是最简单的方法。
    你可以动态生成一个BAT文件。
    Open "A.bat" for output as #1
    Print #1, "net user>j.dat"
    Close #1
    Shell "A.bat",VbHide
    Do Until Dir(j.dat)<>"":DoEvents:Loop
    '---分析---'
    就可以了。
      

  3.   

    不好意思。dir("j.dat")
    还有,不要忘了删除j.dat和a.bat
      

  4.   

    哪位高手知道通过api如何实现吗?
      

  5.   

    取用户的函数很多,我给列举几个吧
    NetUserEnum
    NetQueryDisplayInformation
    NetLocalGroupAddMembers
    ====================================
    枚举所有的用户
    NetUserEnum
    The NetUserEnum function provides information about all user accounts on a server. NET_API_STATUS NetUserEnum(
      LPCWSTR servername,    
      DWORD level,           
      DWORD filter,          
      LPBYTE *bufptr,        
      DWORD prefmaxlen,      
      LPDWORD entriesread,   
      LPDWORD totalentries,  
      LPDWORD resume_handle  
    );
    ----------------------------------------
    获取所有的用户、组等的信息
    NetQueryDisplayInformation
    The NetQueryDisplayInformation function returns user account, computer, or group account information. Call this function to quickly enumerate account information for display in user interfaces.NET_API_STATUS NetQueryDisplayInformation(
      LPCWSTR ServerName,            
      DWORD Level,                   
      DWORD Index,                   
      DWORD EntriesRequested,        
      DWORD PreferredMaximumLength,  
      LPDWORD ReturnedEntryCount,    
      PVOID *SortedBuffer            
    );----------------------------------------
    返回用户列表
    NetLocalGroupGetMembers
    The NetLocalGroupGetMembers function retrieves a list of the members of a particular local group in the security database. Local group members can be users or global groups.NET_API_STATUS NetLocalGroupGetMembers(
      LPCWSTR servername,        
      LPCWSTR localgroupname,    
      DWORD level,               
      LPBYTE *bufptr,            
      DWORD prefmaxlen,          
      LPDWORD entriesread,       
      LPDWORD totalentries,      
      PDWORD_PTR resumehandle    
    );
    ----------------------------------------
    添加用户
    NetLocalGroupAddMembers
    The NetLocalGroupAddMembers function adds membership of one or more existing user accounts or global group accounts to an existing local group. The function does not change the membership status of users or global groups that are currently members of the local group.
    NET_API_STATUS NetLocalGroupAddMembers(
      LPCWSTR servername,     
      LPCWSTR groupname,      
      DWORD level,            
      LPBYTE buf,             
      DWORD totalentries      
    );
    ----------------------------------------
    删除用户
    NetLocalGroupDelMembers
    The NetLocalGroupDelMembers function removes one or more members from an existing local group. Local group members can be users or global groupsNET_API_STATUS NetLocalGroupDelMembers(
      LPCWSTR servername, 
      LPCWSTR groupname,  
      DWORD level,        
      LPBYTE buf,         
      DWORD totalentries  
    );
    ---------------------------------------------
    ===========================
    下面是有关组的函数
    ------------------------
    枚举本地用户组
    NetLocalGroupEnum
    The NetLocalGroupEnum function returns information about each local group account on the specified server.NET_API_STATUS NetLocalGroupEnum(
      LPCWSTR servername,      
      DWORD level,             
      LPBYTE *bufptr,          
      DWORD prefmaxlen,        
      LPDWORD entriesread,     
      LPDWORD totalentries,    
      PDWORD_PTR resumehandle  
    );
    -------------------------------------
    创建组
    NetLocalGroupAdd
    The NetLocalGroupAdd function creates a local group in the security database.NET_API_STATUS NetLocalGroupAdd(
      LPCWSTR servername, 
      DWORD level,        
      LPBYTE buf,         
      LPDWORD parm_err    
    );
    ------------------------------------------
    删除组
    NetLocalGroupDel
    The NetLocalGroupDel function deletes a local group account and all its members from the security database.
    NET_API_STATUS NetLocalGroupDel(
      LPCWSTR servername,  
      LPCWSTR groupname    
    );========================
    抛砖引玉而已,其它的如果楼主还有需要的话,查MSDN好了