CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
英特尔®游戏设计大赛100美元现金周周送 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  VB >  API

WIN2000新建立用户是怎么才能记它作为"用户不能更改密码"和"密码永不过期"选中?

楼主m1_1m(我离高手还好远)2003-08-04 15:55:19 在 VB / API 提问

也就是新建立一个"用户不能更改密码"和"密码永不过期"的用户!  
  用   net   user   abc   123   /add  
  只能加密码! 问题点数:20、回复次数:8Top

1 楼m1_1m(我离高手还好远)回复于 2003-08-04 16:15:09 得分 0

upTop

2 楼m1_1m(我离高手还好远)回复于 2003-08-04 20:01:47 得分 0

现在的高人都哪里去了Top

3 楼redwrite(红妆素裹)回复于 2003-08-18 13:06:46 得分 2

upTop

4 楼hc_z(石泉)回复于 2003-08-18 15:44:18 得分 2

gzTop

5 楼ch21st(www.blanksoft.com)回复于 2003-08-18 16:45:00 得分 14

NT用户管理  
  Option   Explicit  
   
   
        Option   Base   0           '   Important   assumption   for   this   code  
   
        Type   MungeLong  
            X   As   Long  
            Dummy   As   Integer  
        End   Type  
   
        Type   MungeInt  
            XLo   As   Integer  
            XHi   As   Integer  
            Dummy   As   Integer  
        End   Type  
   
        Type   TUser0                                         '   Level   0  
            ptrName   As   Long  
        End   Type  
   
        Type   TUser1                                         '   Level   1  
            ptrName   As   Long  
            ptrPassword   As   Long  
            dwPasswordAge   As   Long  
            dwPriv   As   Long  
            ptrHomeDir   As   Long  
            ptrComment   As   Long  
            dwFlags   As   Long  
            ptrScriptPath   As   Long  
        End   Type  
   
        '  
        '   for   dwPriv  
        '  
        Const   USER_PRIV_MASK   =   &H3  
        Const   USER_PRIV_GUEST   =   &H0  
        Const   USER_PRIV_USER   =   &H1  
        Const   USER_PRIV_ADMIN   =   &H2  
   
        '  
        '   for   dwFlags  
        '  
        Const   UF_SCRIPT   =   &H1  
        Const   UF_ACCOUNTDISABLE   =   &H2  
        Const   UF_HOMEDIR_REQUIRED   =   &H8  
        Const   UF_LOCKOUT   =   &H10  
        Const   UF_PASSWD_NOTREQD   =   &H20  
        Const   UF_PASSWD_CANT_CHANGE   =   &H40  
        Const   UF_NORMAL_ACCOUNT   =   &H200           '   Needs   to   be   ORed   with   the  
                                                                                '   other   flags  
   
        '  
        '   for   lFilter  
        '  
        Const   FILTER_NORMAL_ACCOUNT   =   &H2  
   
        Declare   Function   NetGetDCName   Lib   "NETAPI32.DLL"   (ServerName   As   Byte,   _  
        DomainName   As   Byte,   DCNPtr   As   Long)   As   Long  
   
        Declare   Function   NetUserDel   Lib   "NETAPI32.DLL"   (ServerName   As   Byte,   _  
        UserName   As   Byte)   As   Long  
   
        Declare   Function   NetGroupAddUser   Lib   "NETAPI32.DLL"   (ServerName   As   _  
        Byte,   GroupName   As   Byte,   UserName   As   Byte)   As   Long  
   
        Declare   Function   NetGroupDelUser   Lib   "NETAPI32.DLL"   (ServerName   As   _  
        Byte,   GroupName   As   Byte,   UserName   As   Byte)   As   Long  
   
        '   Add   using   Level   1   user   structure  
        Declare   Function   NetUserAdd1   Lib   "NETAPI32.DLL"   Alias   "NetUserAdd"   _  
        (ServerName   As   Byte,   ByVal   Level   As   Long,   Buffer   As   TUser1,   ParmError   _  
        As   Long)   As   Long  
   
        '   Enumerate   using   Level   0   user   structure  
        Declare   Function   NetUserEnum0   Lib   "NETAPI32.DLL"   Alias   "NetUserEnum"   _  
        (ServerName   As   Byte,   ByVal   Level   As   Long,   ByVal   lFilter   As   Long,   _  
        Buffer   As   Long,   ByVal   PrefMaxLen   As   Long,   EntriesRead   As   Long,   _  
        TotalEntries   As   Long,   ResumeHandle   As   Long)   As   Long  
   
        Declare   Function   NetGroupEnumUsers0   Lib   "NETAPI32.DLL"   Alias   _  
        "NetGroupGetUsers"   (ServerName   As   Byte,   GroupName   As   Byte,   _  
        ByVal   Level   As   Long,   Buffer   As   Long,   ByVal   PrefMaxLen   As   Long,   _  
        EntriesRead   As   Long,   TotalEntries   As   Long,   ResumeHandle   As   Long)   As   Long  
   
        Declare   Function   NetGroupEnum0   Lib   "NETAPI32.DLL"   Alias   "NetGroupEnum"   _  
        (ServerName   As   Byte,   ByVal   Level   As   Long,   Buffer   As   Long,   ByVal   _  
        PrefMaxLen   As   Long,   EntriesRead   As   Long,   TotalEntries   As   Long,   _  
        ResumeHandle   As   Long)   As   Long  
   
        Declare   Function   NetUserGetGroups0   Lib   "NETAPI32.DLL"   Alias   _  
        "NetUserGetGroups"   (ServerName   As   Byte,   UserName   As   Byte,   _  
        ByVal   Level   As   Long,   Buffer   As   Long,   ByVal   PrefMaxLen   As   Long,   _  
        EntriesRead   As   Long,   TotalEntries   As   Long)   As   Long  
   
        Declare   Function   NetAPIBufferFree   Lib   "NETAPI32.DLL"   Alias   _  
        "NetApiBufferFree"   (ByVal   Ptr   As   Long)   As   Long  
   
        Declare   Function   NetAPIBufferAllocate   Lib   "NETAPI32.DLL"   Alias   _  
        "NetApiBufferAllocate"   (ByVal   ByteCount   As   Long,   Ptr   As   Long)   As   Long  
   
        Declare   Function   PtrToStr   Lib   "Kernel32"   Alias   "lstrcpyW"   _  
        (RetVal   As   Byte,   ByVal   Ptr   As   Long)   As   Long  
   
        Declare   Function   StrToPtr   Lib   "Kernel32"   Alias   "lstrcpyW"   _  
        (ByVal   Ptr   As   Long,   Source   As   Byte)   As   Long  
   
        Declare   Function   PtrToInt   Lib   "Kernel32"   Alias   "lstrcpynW"   _  
        (RetVal   As   Any,   ByVal   Ptr   As   Long,   ByVal   nCharCount   As   Long)   As   Long  
   
        Declare   Function   StrLen   Lib   "Kernel32"   Alias   "lstrlenW"   _  
        (ByVal   Ptr   As   Long)   As   Long  
   
        Function   AddUserToGroup(ByVal   SName   As   String,   _  
        ByVal   GName   As   String,   ByVal   UName   As   String)   As   Long  
        '  
        '   This   only   adds   users   to   global   groups   -   not   to   local   groups  
        '  
        Dim   SNArray()   As   Byte,   GNArray()   As   Byte,   UNArray()   As   Byte,   _  
        Result   As   Long  
            SNArray   =   SName   &   vbNullChar  
            GNArray   =   GName   &   vbNullChar  
            UNArray   =   UName   &   vbNullChar  
            Result   =   NetGroupAddUser(SNArray(0),   GNArray(0),   UNArray(0))  
            If   Result   =   2220   Then   Debug.Print   _  
        "There   is   no   **GLOBAL**   group   '"   &   GName   &   "'"  
            AddUserToGroup   =   Result  
        End   Function  
   
        Function   DelUser(ByVal   SName   As   String,   ByVal   UName   As   String)   As   Long  
        Dim   UNArray()   As   Byte,   SNArray()   As   Byte  
            UNArray   =   UName   &   vbNullChar  
            SNArray   =   SName   &   vbNullChar  
            DelUser   =   NetUserDel(SNArray(0),   UNArray(0))  
        End   Function  
   
        Function   DelUserFromGroup(ByVal   SName   As   String,   _  
        ByVal   GName   As   String,   ByVal   UName   As   String)   As   Long  
        '  
        '   This   only   deletes   users   from   global   groups   -   not   local   groups  
        '  
        Dim   SNArray()   As   Byte,   GNArray()   As   Byte,   UNArray()   As   Byte,   _  
        Result   As   Long  
            SNArray   =   SName   &   vbNullChar  
            GNArray   =   GName   &   vbNullChar  
            UNArray   =   UName   &   vbNullChar  
            Result   =   NetGroupDelUser(SNArray(0),   GNArray(0),   UNArray(0))  
            If   Result   =   2220   Then   Debug.Print   _  
        "There   is   no   **GLOBAL**   group   '"   &   GName   &   "'"  
            DelUserFromGroup   =   Result  
        End   Function  
   
  Top

6 楼ch21st(www.blanksoft.com)回复于 2003-08-18 16:45:31 得分 0

Function   EnumerateGroups(ByVal   SName   As   String,   _  
        ByVal   UName   As   String)   As   Long  
          Dim   Result   As   Long,   BufPtr   As   Long,   EntriesRead   As   Long,   _  
        TotalEntries   As   Long,   ResumeHandle   As   Long,   BufLen   As   Long,   _  
        SNArray()   As   Byte,   GNArray(99)   As   Byte,   UNArray()   As   Byte,   _  
        GName   As   String,   I   As   Integer,   UNPtr   As   Long,   _  
        TempPtr   As   MungeLong,   TempStr   As   MungeInt  
   
            SNArray   =   SName   &   vbNullChar               '   Move   to   byte   array  
            UNArray   =   UName   &   vbNullChar               '   Move   to   Byte   array  
            BufLen   =   255                                               '   Buffer   size  
            ResumeHandle   =   0                                       '   Start   with   the   first   entry  
   
            Do  
                If   UName   =   ""   Then  
                    Result   =   NetGroupEnum0(SNArray(0),   0,   BufPtr,   BufLen,   _  
        EntriesRead,   TotalEntries,   ResumeHandle)  
                Else  
                    Result   =   NetUserGetGroups0(SNArray(0),   UNArray(0),   0,   BufPtr,   _  
        BufLen,   EntriesRead,   TotalEntries)  
                End   If  
                EnumerateGroups   =   Result  
                If   Result   <>   0   And   Result   <>   234   Then         '   234   means   multiple   reads  
                                                                                                  '   required  
                    Debug.Print   "Error   "   &   Result   &   "   enumerating   group   "   &   _  
        EntriesRead   &   "   of   "   &   TotalEntries  
                    Exit   Function  
                End   If  
                For   I   =   1   To   EntriesRead  
                    '   Get   pointer   to   string   from   beginning   of   buffer  
                    '   Copy   4   byte   block   of   memory   in   2   steps  
                    Result   =   PtrToInt(TempStr.XLo,   BufPtr   +   (I   -   1)   *   4,   2)  
                    Result   =   PtrToInt(TempStr.XHi,   BufPtr   +   (I   -   1)   *   4   +   2,   2)  
                    LSet   TempPtr   =   TempStr   '   munge   2   Integers   to   a   Long  
                    '   Copy   string   to   array   and   convert   to   a   string  
                    Result   =   PtrToStr(GNArray(0),   TempPtr.X)  
                    GName   =   Left(GNArray,   StrLen(TempPtr.X))  
                    Debug.Print   "Group:   "   &   GName  
                Next   I  
            Loop   Until   EntriesRead   =   TotalEntries  
        '   The   above   condition   only   valid   for   reading   accounts   on   NT  
        '   but   not   OK   for   OS/2   or   LanMan  
   
            Result   =   NetAPIBufferFree(BufPtr)                   '   Don't   leak   memory  
   
        End   Function  
   
        Function   EnumerateUsers(ByVal   SName   As   String,   ByVal   GName   As   String)   _  
        As   Long  
            Dim   Result   As   Long,   BufPtr   As   Long,   EntriesRead   As   Long,   _  
        TotalEntries   As   Long,   ResumeHandle   As   Long,   BufLen   As   Long,   _  
        SNArray()   As   Byte,   GNArray()   As   Byte,   UNArray(99)   As   Byte,   _  
        UName   As   String,   I   As   Integer,   UNPtr   As   Long,   TempPtr   As   MungeLong,   _  
        TempStr   As   MungeInt  
   
            SNArray   =   SName   &   vbNullChar               '   Move   to   byte   array  
            GNArray   =   GName   &   vbNullChar               '   Move   to   Byte   array  
            BufLen   =   255                                               '   Buffer   size  
            ResumeHandle   =   0                                       '   Start   with   the   first   entry  
   
            Do  
                If   GName   =   ""   Then  
                    Result   =   NetUserEnum0(SNArray(0),   0,   FILTER_NORMAL_ACCOUNT,   _  
        BufPtr,   BufLen,   EntriesRead,   TotalEntries,   ResumeHandle)  
                Else  
                    Result   =   NetGroupEnumUsers0(SNArray(0),   GNArray(0),   0,   BufPtr,   _  
        BufLen,   EntriesRead,   TotalEntries,   ResumeHandle)  
                End   If  
                EnumerateUsers   =   Result  
                If   Result   <>   0   And   Result   <>   234   Then         '   234   means   multiple   reads  
                                                                                                  '   required  
                    Debug.Print   "Error   "   &   Result   &   "   enumerating   user   "   _  
        &   EntriesRead   &   "   of   "   &   TotalEntries  
                    If   Result   =   2220   Then   Debug.Print   _  
        "There   is   no   **GLOBAL**   group   '"   &   GName   &   "'"  
                    Exit   Function  
                End   If  
                For   I   =   1   To   EntriesRead  
                    '   Get   pointer   to   string   from   beginning   of   buffer  
                    '   Copy   4-byte   block   of   memory   in   2   steps  
                    Result   =   PtrToInt(TempStr.XLo,   BufPtr   +   (I   -   1)   *   4,   2)  
                    Result   =   PtrToInt(TempStr.XHi,   BufPtr   +   (I   -   1)   *   4   +   2,   2)  
                    LSet   TempPtr   =   TempStr   '   munge   2   integers   into   a   Long  
                    '   Copy   string   to   array  
                    Result   =   PtrToStr(UNArray(0),   TempPtr.X)  
                    UName   =   Left(UNArray,   StrLen(TempPtr.X))  
                    Debug.Print   "User:   "   &   UName  
                Next   I  
            Loop   Until   EntriesRead   =   TotalEntries  
        '   The   above   condition   is   only   valid   for   reading   accounts   on   Windows   NT,  
        '   but   is   not   OK   for   OS/2   or   LanMan  
   
            Result   =   NetAPIBufferFree(BufPtr)                   '   Don't   leak   memory  
   
        End   Function  
   
        Function   GetPrimaryDCName(ByVal   MName   As   String,   _  
        ByVal   DName   As   String)   As   String  
        Dim   Result   As   Long,   DCName   As   String,   DCNPtr   As   Long  
        Dim   DNArray()   As   Byte,   MNArray()   As   Byte,   DCNArray(100)   As   Byte  
            MNArray   =   MName   &   vbNullChar  
            DNArray   =   DName   &   vbNullChar  
            Result   =   NetGetDCName(MNArray(0),   DNArray(0),   DCNPtr)  
            If   Result   <>   0   Then  
                Debug.Print   "Error:   "   &   Result  
                Exit   Function  
            End   If  
            Result   =   PtrToStr(DCNArray(0),   DCNPtr)  
            Result   =   NetAPIBufferFree(DCNPtr)  
            DCName   =   DCNArray()  
            GetPrimaryDCName   =   DCName  
        End   Function  
   
        Function   AddUser(ByVal   SName   As   String,   ByVal   UName   As   String,   _  
        ByVal   PWD   As   String)   As   Long  
        Dim   Result   As   Long,   UNPtr   As   Long,   PWDPtr   As   Long,   ParmError   As   Long  
        Dim   SNArray()   As   Byte,   UNArray()   As   Byte,   PWDArray()   As   Byte  
        Dim   UserStruct   As   TUser1  
        '  
        '   Move   to   byte   arrays  
        '  
            SNArray   =   SName   &   vbNullChar  
            UNArray   =   UName   &   vbNullChar  
            PWDArray   =   PWD   &   vbNullChar  
        '  
        '   Allocate   buffer   space  
        '  
            Result   =   NetAPIBufferAllocate(UBound(UNArray)   +   1,   UNPtr)  
            Result   =   NetAPIBufferAllocate(UBound(PWDArray)   +   1,   PWDPtr)  
        '  
        '   Copy   arrays   to   the   buffer  
        '  
            Result   =   StrToPtr(UNPtr,   UNArray(0))  
            Result   =   StrToPtr(PWDPtr,   PWDArray(0))  
        '  
        '   Fill   the   structure  
        '  
            With   UserStruct  
                .ptrName   =   UNPtr  
                .ptrPassword   =   PWDPtr  
                .dwPasswordAge   =   3  
                .dwPriv   =   USER_PRIV_USER  
                .ptrHomeDir   =   0  
                .ptrComment   =   0  
                .dwFlags   =   UF_NORMAL_ACCOUNT   Or   UF_SCRIPT  
                .ptrScriptPath   =   0  
            End   With  
        '  
        '   Add   the   user  
        '  
            Result   =   NetUserAdd1(SNArray(0),   1,   UserStruct,   ParmError)  
            AddUser   =   Result  
            If   Result   <>   0   Then  
                Debug.Print   "Error   "   &   Result   &   "   in   parameter   "   &   ParmError   _  
        &   "   when   adding   user   "   &   UName  
            End   If  
        '  
        '   Release   buffers   from   memory  
        '  
            Result   =   NetAPIBufferFree(UNPtr)  
            Result   =   NetAPIBufferFree(PWDPtr)  
   
        End   Function  
   
  Top

7 楼ch21st(www.blanksoft.com)回复于 2003-08-18 16:53:51 得分 0

你要注意的就是建立用户是传入的那个结构TUser1  
  这个实例用的是一级,你可以用是三级用户结构,有如下信息  
  Private   Type   USER_INFO_3  
          usri3_name   As   Long  
          usri3_password   As   Long  
          usri3_password_age   As   Long  
          usri3_priv   As   Long  
          usri3_home_dir   As   Long  
          usri3_comment   As   Long  
          usri3_flags   As   Long  
          usri3_script_path   As   Long  
          usri3_auth_flags   As   Long  
          usri3_full_name   As   Long  
          usri3_usr_comment   As   Long  
          usri3_parms   As   Long  
          usri3_workstations   As   Long  
          usri3_last_logon   As   Long  
          usri3_last_logoff   As   Long  
          usri3_acct_expires   As   Long  
          usri3_max_storage   As   Long  
          usri3_units_per_week   As   Long  
          usri3_logon_hours   As   Byte  
          usri3_bad_pw_count   As   Long  
          usri3_num_logons   As   Long  
          usri3_logon_server   As   String  
          usri3_country_code   As   Long  
          usri3_code_page   As   Long  
          usri3_user_id   As   Long  
          usri3_primary_group_id   As   Long  
          usri3_profile   As   Long  
          usri3_home_dir_drive   As   Long  
          usri3_password_expired   As   Long  
  End   Type  
  Top

8 楼lhfcsdn(http://shop33840643.taobao.com/)回复于 2003-10-29 14:34:28 得分 2

upTop

相关问题

  • Windows2000密码过期问题!!!
  • 如何更改linux密码
  • 有关SQL更改密码的问题。
  • +++++用户登陆密码更改问题+++++
  • ORACLE如何更改internal的密码
  • owa中更改密码的问题
  • mysql如何更改root的密码?
  • 如何更改ACCESS的密码??
  • ADO更改ACCESS密码的问题
  • 域用户密码更改问题。

关键词

  • os/2
  • 密码
  • 用户
  • uf
  • priv
  • const
  • as long
  • integer
  • user
  • type

得分解答快速导航

  • 帖主:m1_1m
  • redwrite
  • hc_z
  • ch21st
  • lhfcsdn

相关链接

  • Visual Basic类图书
  • Visual Basic类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo