C++ 枚举本地主机所有用户、用户基本信息

上一篇 / 下一篇  2011-04-07 00:28:09 / 个人分类:.NET

]^)s4LYA kr0#include "iostream"
6kv{3_v8jc;C0#include "windows.h"
Y0b,|)an,GF0#include "lm.h"
w wu+D}R7|-l3y0#include "assert.h"51Testing软件测试网X%K F Xg:Vvf
#include "string"
O-g,v7G6VRj5H%i0#include "time.h"51Testing软件测试网O.~ rw1r U
using namespace std;51Testing软件测试网;A!y(\%`*T!Ft4K#r

1fy!]WB/R0#pragma comment(lib,"netapi32.lib")

%U I,WBNn7| N6X p(B,?051Testing软件测试网V3^/p,k)wn

51Testing软件测试网7f#n;q6R1R
//判断帐户状态:数组各个值对应的意义如下51Testing软件测试网'\7b$Ro#E![N
/*

;g'Zpr:U-wU051Testing软件测试网jQ7[ S6NC HN&_

序号 Value              Mean                                          Calendar Value
9Q k,O4_W,YH001   UF_SCRIPT      登录脚本执行                                      1   
-`)D1VJ)kl'm,_3u002   UF_ACCOUNTDISABLE    用户帐户不可用                   2
m{CT*t%D#cg&d#y003      
VwV-?F004   UF_HOMEDIR_REQUIRED    要求有用户目录              8
8eG1t q&JUJc002   UF_LOCKOUT      帐户锁定                                          16
#z!Me/FEX2~006   UF_PASSWD_NOTREQD    不要求用户密码                3251Testing软件测试网2P-uD6bf,~8p
07   UF_PASSWD_CANT_CHANGE   不能更改密码            64

l d \YY^YIr5V051Testing软件测试网+z0htRe j

08

cca:fOw g051Testing软件测试网Ezcn6ny7?)Ap2R^

   以下为帐户类型:51Testing软件测试网+U h$d*b$m
09   UF_TEMP_DUPLICATE_ACCOUNT 域用户帐户           256
B5wM6z/E010   UF_NORMAL_ACCOUNT    普通帐户                            51251Testing软件测试网$F_[_3_iPr
11
:US B+d h0e012   UF_INTERDOMAIN_TRUST_ACCOUNT域内可信任帐户   2048
mK.KeWNj013   UF_WORKSTATION_TRUST_ACCOUNT工作组可信任帐户 409651Testing软件测试网D B)k9C-XSK
14   UF_SERVER_TRUST_ACCOUNT   备份域控制器帐户 819251Testing软件测试网I?!K8\/]zh
15
LXK-m_:i| V!F01651Testing软件测试网S-Q'} X T)cW1`ia uQ
17   UF_DONT_EXPIRE_PASSWD   密码不过期                  65536

\L1m$d T,{&_/V'm0

z1l0[*n)E8~H W%L0说明:用ToBinary(int,int)这个函数判断各个序号对应的值是否为真。
*B7K Vw RxVi0*/51Testing软件测试网VC.i(W+Dy
int ToBinary(long n,int k)51Testing软件测试网}C7N| N KYC
{51Testing软件测试网zWnrlVQ` { @
int num[17];
w;s9FP8V2aD0int i=16;
e,^4C.le0//密码永不过期51Testing软件测试网 m%u i{vF-@8Z c/Y)Kn
long m=n;51Testing软件测试网;L e#ULJ n.]g+?p;?F
if(k>17||k<1)
*Hl{$o9e-}%z0   k=1;
"~8q;z2G&i qy7f0while(m!=0)51Testing软件测试网7`5s+Kj"S'hOz
{
IFp"BEe0  
W.K2mgAo U2C,`.h A0   num[i]=m%2;51Testing软件测试网6D*@ XK Y ]
   m=m/2;
6^h ~v3|6~0   i--;51Testing软件测试网['CJbI1lXbF6s

vnTo%IZ)N0}
"i.KM,C'^/N!a0num[i]='\0';
,r"H,H;}D:m?-@0return num[17-k];51Testing软件测试网G5p5Wz4~Z K
}51Testing软件测试网H!R5LE SS8E
int GetAllUser()51Testing软件测试网3_3E[4re2`\
{
a2wW9VE.\ @0LPUSER_INFO_1 pBuf = NULL;51Testing软件测试网"\y'U a#x
LPUSER_INFO_1 pTmpBuf;51Testing软件测试网5_&Uv)O ?;b"F

f Y jk'o?;T0DWORD dwLevel = 1;51Testing软件测试网'h7S2@8e8a+Ye$HhA
DWORD dwPrefMaxLen = MAX_PREFERRED_LENGTH;
mc t#c$U&F0DWORD dwEntriesRead = 0;51Testing软件测试网1L;O yW&l)l@ s
DWORD dwTotalEntries = 0;
0K] m,J6XQV+FK0DWORD dwResumeHandle = 0;51Testing软件测试网Eue6l(Y(]Z#`
DWORD i;51Testing软件测试网6CcEP(?*H-\,g"}
DWORD dwTotalCount = 0;
8L g @|Vv$r0NET_API_STATUS nStatus;51Testing软件测试网 y#J5NdTx uCG
LPTSTR pszServerName = NULL;51Testing软件测试网P$q4S!{%`q`$g

51Testing软件测试网BLA*XH:n ?

do
;LB)p tUz N0{51Testing软件测试网&B4vxUd%R*M
   nStatus = NetUserEnum(NULL,51Testing软件测试网c-Y nq};k
    dwLevel,51Testing软件测试网.gcnm3U%f I
    FILTER_NORMAL_ACCOUNT, // global users
0vrx[o@-jzK0    (LPBYTE*)&pBuf,
5m$YQ y9K&T/r0    dwPrefMaxLen,51Testing软件测试网!Iu:h,?(uEc8Ad
    &dwEntriesRead,
|%[pV7H,E0    &dwTotalEntries,
!uE:Wp%lC"R0    &dwResumeHandle);

DZA b"d+M&r0

#|WD~N0   //
V)G fa.P+O%f3}'w0   // If the call succeeds,51Testing软件测试网cC/]9g8dU;|
   //
U/G!x3E?n0   if ((nStatus == NERR_Success) || (nStatus == ERROR_MORE_DATA))
X_+N&YR0   {51Testing软件测试网 K'D7TOU8M l1We-K*h(Zb
    if ((pTmpBuf = pBuf) != NULL)
W&L7z+Fte0    {
Ip(\we o |0    //
K%t }+a\@$~f3K QQ0    // Loop through the entries.51Testing软件测试网@~_~8bC K1_
    //
RC)@+yrY0     for (i = 0; (i < dwEntriesRead); i++)
Z psn#b7]} NS0     {51Testing软件测试网!Z$DM@:Hw-y~tg
      assert(pTmpBuf != NULL);51Testing软件测试网y S[dMU#X2ot

51Testing软件测试网8g_CH;qb-o(K

      if (pTmpBuf == NULL)
9iF AK3T4I{-CQ.j J0      {
2U8h&U^ CaYe~0       fprintf(stderr, "An access violation has occurred\n");
l ]8v9E*}w"I#t }0       break;51Testing软件测试网]!PDS$\O Xxe
      }
1?.r4y3`)A j QuL#Z0      //
a k#Yt[,r_0      // Print the name of the user account.
.`:P@fW`0      //
QtA/N,k7W0   /*
-\+Q"dFm!h!uPH0   typedef struct _USER_INFO_1 {51Testing软件测试网"t`jd|.R1`{?
     LPWSTR    usri1_name;   //用户名
uCYtk/fN#DyW0     LPWSTR    usri1_password; //用户密码51Testing软件测试网5F.I_6B3xX$cVDWA
     DWORD     usri1_password_age; //当前密码使用时间(单位:秒)
9HGQl'l1Ok&o0     DWORD     usri1_priv;   //用户权限 0 来宾; 1 普通用户; 2 管理员.51Testing软件测试网;]P}B#AB
     LPWSTR    usri1_home_dir; //
-Y,d|\o#Hrk|I0     LPWSTR    usri1_comment; //备注,可能为NULL
i[r5y&|[UG0     DWORD     usri1_flags;   //51Testing软件测试网 vw/\/r/w
     LPWSTR    usri1_script_path; //返回Unicode string,包含用户登录的脚本。可以为NULL
f4vE$W-HEq0    }USER_INFO_1, *PUSER_INFO_1, *LPUSER_INFO_1;

VY.Y-A&N0

6rj;B7H]o]0   */
G Ifa+k s3p-z5G0   wprintf(L"Account No.%d\n",dwTotalCount+1);

4[B*}{ ? o7X7O051Testing软件测试网5W"b!D4F6M Y:{

   LPUSER_INFO_3 bufptr=NULL;
vROe(pH3q3Y$AC0   LPUSER_INFO_2 buf=NULL;51Testing软件测试网&a/N+N]rB
   NET_API_STATUS t3,t2;51Testing软件测试网1b2VgQYE!oFL
   t3=NetUserGetInfo(0,pTmpBuf->usri1_name,3,(LPBYTE*)&bufptr);51Testing软件测试网 NU*U8R#~YS
   t2=NetUserGetInfo(0,pTmpBuf->usri1_name,2,(LPBYTE*)&buf);51Testing软件测试网)\Q+x F*a*m
   //帐户名称:
'b"LCa.g2U?ys;q0   wprintf(L"\t Account Name: %s \n",bufptr->usri3_name);
9u*Y9As"b'Y_0   //上次登录时间:单位,秒;计算起始时间为1970年1月1日00:0051Testing软件测试网-w.RhdC c V
   if(bufptr->usri3_last_logon==0)
PH7ln,e+W0    cout<<"\t Account Last Logon Time: "<<"上次登录时间未知"<<endl;51Testing软件测试网g3v&vDuwF
   else51Testing软件测试网W+^6q|bf0r,g
   {51Testing软件测试网7Zo3v.s$tn]Ts-VU
    long m=bufptr->usri3_last_logon;
/r:Q u1N7kZ1?|0    time_t last;51Testing软件测试网M4S/J] {,p
    last = m;
|(Hc.G'j9u Y|0    cout<<"\t Account Last Logon Time: "<<ctime(&last);
?-lw6p!z8| TlP n0   }51Testing软件测试网LV c4BN,@^/[

G0m!ic J*Lh0   //密码过期时间:单位,秒;计算起始时间为1970年1月1日00:00. 如果为 0 ,表示永不过期
)v*r S6p.||m0   if(bufptr->usri3_password_expired==0||bufptr->usri3_password_expired==NULL)51Testing软件测试网7AKd_ g"QRG.a.|/|F
    cout<<"\t Password Expiried Time: "<<"密码永不过期"<<endl;
)n2]kM7s-v h E#I DQ0   else
Y.c$?a$Vw"K0   {51Testing软件测试网 n1h)nI9O h*Ne
    long n=bufptr->usri3_password_expired;51Testing软件测试网K!KimrH CV
    time_t pwd;51Testing软件测试网a4o&L4ub
    pwd = n;
!S"E0w6lly-? j0    cout<<"\t Password Expiried Time: "<<ctime(&pwd)<<endl;51Testing软件测试网%i9Xp*K-d
   }

8?%[&}:V9i5x051Testing软件测试网9N%U*pePz9rU8VdW

   //判断账户过期时间:如果过期时间为:65536*65536-1,表示永不过期
.q#E4}"Q;Hn0/* if(buf->usri2_acct_expires==4294967295)51Testing软件测试网I ?Z2D[
    cout<<"\t Account Expiried Time:"<<"帐户永不过期"<<endl;51Testing软件测试网i5|N~v`7lK
   else
!`MHsg&x_0   {51Testing软件测试网4D+z _}t"TM2a!xx
    long k=buf->usri2_acct_expires;
+xB+A1}-j X*uC;W.V0    time_t acct;
2UD+N&~#m0    acct = k;
sPPPD(@9zt,\0\7]0    cout<<"\t Account Expiried Time:"<<ctime(&acct)<<endl;
@8oe8n` n8r0   }
@4I,K4\ ~M ?0   */
6i7j E {KG0   //判断帐户状态 usri2_flags:51Testing软件测试网:n@QM3E8M7^6C$J#O
   /*51Testing软件测试网-Eq.K.[dl
   value       mean     int   51Testing软件测试网tM[}!B9Pb TI
   UF_SCRIPT      登录脚本执行   1   
a"F.Hxkf0   UF_ACCOUNTDISABLE    用户帐户不可用   2
xu,y }D0      51Testing软件测试网-U1B#yp?v+i
   UF_HOMEDIR_REQUIRED    要求有用户目录   851Testing软件测试网;|~l$Xn NYI
   UF_LOCKOUT      帐户锁定    1651Testing软件测试网x6V:YvX*r:SZ:c%e
   UF_PASSWD_NOTREQD    不要求用户密码   32
6_zg&rT6yp0   UF_PASSWD_CANT_CHANGE   不能更改密码   64

.mbS#\'f%{1J#}G%}0

8R1U(g^#tko&p0   UF_DONT_EXPIRE_PASSWD   密码不过期    65536

+j(O9T6U%a`&AgV051Testing软件测试网 o&I:W|~'Yj2J/X

   以下为帐户类型:51Testing软件测试网/z{_5I!Q$Q5N
   UF_TEMP_DUPLICATE_ACCOUNT 域用户帐户    25651Testing软件测试网 }#rb0cw6n
   UF_NORMAL_ACCOUNT    普通帐户    51251Testing软件测试网%?0|)B3ne$l

51Testing软件测试网(f9{sX"T1w a:mPQt

   UF_INTERDOMAIN_TRUST_ACCOUNT域内可信任帐户   2048
/_z'azt0|*k;b!Z$L4`$N0   UF_WORKSTATION_TRUST_ACCOUNT工作组可信任帐户 409651Testing软件测试网u&j J$[%?xW
   UF_SERVER_TRUST_ACCOUNT   备份域控制器帐户 819251Testing软件测试网o6Hz X9`z'P$kyK
  51Testing软件测试网1a$g Ih,J M"Y
   */51Testing软件测试网%BL zJW:Cg w{"v
   long n=buf->usri2_flags;
,|9eAa7MAN3[0   //帐户状态:
I3dJC V0   if(ToBinary(n,2))
Le3e.\ \~ a&]Pcb0    cout<<"\t Account Status : "<<"帐户未启用"<<endl;
`|2U+D1@8j(}"u*?0   else
p"]P*Kh7{0    cout<<"\t Account Status : "<<"帐户已启用"<<endl;
2F1jy0F"}0   //密码是否可更改:51Testing软件测试网)\5W9ykj W9Or
   if(ToBinary(n,7))51Testing软件测试网7p!BJ9b!_m/Rj
    cout<<"\t Password Change : "<<"密码不能更改"<<endl;
"wZ.M*d F;H`s _)B0   else51Testing软件测试网o hF}/@xV6yj {
    cout<<"\t Password Change : "<<"密码可以更改"<<endl;51Testing软件测试网? LN S,WH-W

]"a7V/sJrG0      pTmpBuf++;51Testing软件测试网)e$x9b.s2^q!o6l
      dwTotalCount++;
H|_r3^-ul0oe0     }51Testing软件测试网f9]qz6g9Nk
    }51Testing软件测试网.~sY+s-}N%u:\l
   }
J;y\[ Z"?l"r4As5F6y0   else{
IG @wNLP RY0    fprintf(stderr, "A system error has occurred: %d\n", nStatus);51Testing软件测试网H~/cJ+i Y V^
   }51Testing软件测试网u~x6C+T
   if (pBuf != NULL)51Testing软件测试网+E&y:p o4`pA!X
   {
[ HH7{w1Q)T0    NetApiBufferFree(pBuf);
MA}+y)@0    pBuf = NULL;
O7T PtO/w(SRx0   }
Dthj }&cX+e0}while(nStatus == ERROR_MORE_DATA);51Testing软件测试网Tfa+C` rHhZ#Cb

51Testing软件测试网8X1?:Q1I,t

fprintf(stderr, "\nTotal of %d entries enumerated\n", dwTotalCount);

-j"DA9wY$L%I!~V0

yK\ HZv0return 0;
|,um8ag6F{H0}

m,k$cQ&jz4^Y0

U P^"a(bB d0void main()51Testing软件测试网YnL}'A
{51Testing软件测试网NSZ5K*y*x8?Go'?z

u"Rcf2sKo,\&s0GetAllUser();
] qSoY5e ? h0cin.get();51Testing软件测试网"zv~r4fD%aP!}!P
}

R9B]&?$SQU8a.f0

.~x%AK d0//以上代码在 Viusal C++ 6.0 编译下通过

b1AOo/?!|8]O051Testing软件测试网8y#?7ki?S;@EAg

以下为MSDN帮助文档中的说明:

Whj\kzo,uB0

v(q#h5B&Mx1o0P SY0NetUserGetInfo定义如下:51Testing软件测试网(C F3d0Tf

o*HNTF*Z0NET_API_STATUS NetUserGetInfo(
x {$U"zN5v0LPWSTR
servername, //远程主机名,值为NULL,表示本机。
6r~3OH#{Xos7K] p[!z/q+Q0LPWSTRusername,    //用户名51Testing软件测试网 c~c8O)R*t
DWORDlevel,        //返回对应的 _USER_INF0_ 值:例如,返回0,对应 _USER_INFO_051Testing软件测试网5Qjh6k)JZa(C
LPBYTE*bufptr     51Testing软件测试网d y,xyg*e8r,e;i
);

p],]D0VW0

Parameters

servername
Pointer to a Unicode string containing the name of the remote server on which the function is to execute. A NULL pointer or string specifies the local computer.
username
Pointer to a Unicode string containing the name of the user account on which to return information.
level
Specifies one of the following values to return the level of information provided.
ValueMeaning
0ReturnsUSER_INFO_0structure pointed to inbufptr.
1ReturnsUSER_INFO_1structure pointed to inbufptr.
2ReturnsUSER_INFO_2structure pointed to inbufptr.
3ReturnsUSER_INFO_3structure pointed to inbufptr.
10ReturnsUSER_INFO_10structure pointed to inbufptr.
11ReturnsUSER_INFO_11structure pointed to inbufptr.
20ReturnsUSER_INFO_20structure pointed to inbufptr.
51Testing软件测试网\ T?x q5d8Hf
bufptr
Pointer to the buffer in which the data set with thelevelparameter is stored. The returned buffer should be deallocated using theNetApiBufferFreefunction.

Return Values

#~ N.x3g}!E;Xt0If the function is successful, it returns NERR_SUCCESS.51Testing软件测试网z*b+KE(~ R5|)n'p+x

51Testing软件测试网Dz#vVM+i

If the function fails, the return value is one of the following error codes.51Testing软件测试网;haMY u z/e

51Testing软件测试网r'}uE3t;Y

ValueMeaning
ERROR_ACCESS_DENIEDThe user does not have access to the requested information.
NERR_InvalidComputerThe computer name is invalid.
NERR_UserNotFoundThe user name could not be found.
51Testing软件测试网eHY |*u#Rz

51Testing软件测试网f+fJ4iU

f:x8d$VM0

USER_INFO_0

51Testing软件测试网)c9['A7N/\R4q%ek

TheUSER_INFO_0structure specifies information about a user account.

?W xJ+I c?&fr,rM Q0
typedef struct _USER_INFO_0 {
    LPWSTR    usri0_name;
}USER_INFO_0, *PUSER_INFO_0, *LPUSER_INFO_0;

USER_INFO_2

51Testing软件测试网1_;KL[:Y9gZ9SrC

TheUSER_INFO_2structure contains user information for network accounts.

bhL)?+@_].W2y0
typedef struct _USER_INFO_2 {
    LPWSTR    usri2_name;
    LPWSTR    usri2_password;
    DWORD     usri2_password_age;
    DWORD     usri2_priv;
    LPWSTR    usri2_home_dir;
    LPWSTR    usri2_comment;
    DWORD     usri2_flags;
    LPWSTR    usri2_script_path;
    DWORD     usri2_auth_flags;
    LPWSTR    usri2_full_name;
    LPWSTR    usri2_usr_comment;
    LPWSTR    usri2_parms;
    LPWSTR    usri2_workstations;
    DWORD     usri2_last_logon;
    DWORD     usri2_last_logoff;
    DWORD     usri2_acct_expires;
    DWORD     usri2_max_storage;
    DWORD     usri2_units_per_week;
    PBYTE     usri2_logon_hours;
    DWORD     usri2_bad_pw_count;
    DWORD     usri2_num_logons;
    LPWSTR    usri2_logon_server;
    DWORD     usri2_country_code;
    DWORD     usri2_code_page;
}USER_INFO_2, *PUSER_INFO_2, *LPUSER_INFO_2;

Members

usri2_name
Specifies the name of the user account. ForNetUserSetInfo, this member is ignored. The number of characters in the name cannot exceed the value of UNLEN.
usri2_password
The password for the user specified in theusri2_namemember. The length cannot exceed PWLEN bytes. TheNetUserEnumandNetUserGetInfofunctions return a NULL pointer to maintain password security. By convention, Windows NT limits the length of passwords to LM20_PWLEN characters. This convention allows LAN Manager, Windows 3.x, Windows for Workgroups 3.x, Windows 95, and Windows 98 clients to access a Windows NT server using the account.
usri2_password_age
Specifies the number of seconds elapsed since theusri2_passwordmember was last changed. TheNetUserAddandNetUserSetInfofunctions ignore this member.
usri2_priv
One of three values specifying the level of privilege assigned theusri2_namemember. ForNetUserAdd, this member must be USER_PRIV_USER. ForNetUserSetInfo, this member must be the value returned fromNetUserGetInfoorNetUserEnum. This member can be one of the following values:
ValueMeaning
USER_PRIV_GUESTGuest
USER_PRIV_USERUser
USER_PRIV_ADMINAdministrator
51Testing软件测试网H6~HK'p7|.i
usri2_home_dir
Points to a Unicode string containing the path of the home directory for the user specified in theuser_namemember. The string can be null.
usri2_comment
Points to a Unicode string that contains a comment. The string can be a null string, or it can have any number of characters before the terminating null character.
usri2_flags
Contains values that determine several features. This member can be any of the following values:
ValueMeaning
UF_SCRIPTThe logon script. executed. This value must be set for LAN Manager 2.0 or Windows NT.
UF_ACCOUNTDISABLEThe user's account is disabled.
UF_HOMEDIR_REQUIREDThe home directory is required. This value is ignored in Windows NT.
UF_PASSWD_NOTREQDNo password is required.
UF_PASSWD_CANT_CHANGEThe user cannot change the password.
UF_LOCKOUTThe account is currently locked out. ForNetUserSetInfo, this value can be cleared to unlock a previously locked account. This value cannot be used to lock a previously unlocked account.
UF_DONT_EXPIRE_PASSWDWindows NT:Represents the password, which should never expire on the account.
51Testing软件测试网D1mDP'~N)o:S

/`_`CJi v0The following values describe the account type. Only one value can be set. You cannot change the account type using theNetUserSetInfofunction.

ValueMeaning
UF_NORMAL_ACCOUNTThis is a default account type that represents a typical user.
UF_TEMP_DUPLICATE_ACCOUNTThis is an account for users whose primary account is in another domain. This account provides user access to this domain, but not to any domain that trusts this domain. The User Manager refers to this account type as alocaluser account.
UF_WORKSTATION_TRUST_ACCOUNTThis is a computer account for a Windows NT Workstation or Windows NT Server that is a member of this domain.
UF_SERVER_TRUST_ACCOUNTThis is a computer account for a Windows NT Backup Domain Controller that is a member of this domain.
UF_INTERDOMAIN_TRUST_ACCOUNTThis is apermit to trustaccount for a Windows NT domain thattrustsother domains.
51Testing软件测试网f z)r^\)WP|3s$|

usri2_script_path
Points to a Unicode string specifying the path of the user's logon script, .CMD, .EXE, or .BAT file. The string can be null.
usri2_auth_flags
Specifies an unsigned long integer that contains values that specify the user's operator privileges.

Windows NT:For Windows NT servers, the following restrictions apply:51Testing软件测试网7Gn"y'|6lA%e#]


]3{ E*J4@BH0

l6s|!Xl7O1Djo0ForNetUserGetInfoorNetUserEnum, the appropriate value is returned based on the local group membership. If the user is a member ofPrint Operations, AF_OP_PRINT is set. If the user is a member ofServer Operations, AF_OP_SERVER is set. If the user is a member of theAccount Operations, AF_OP_ACCOUNTS is set. AF_OP_COMM is never set.51Testing软件测试网H?5] W/wN!O

0`8N2w9a&Igb6^t0This member can be one of the following values:

ValueMeaning
AF_OP_PRINTThe print operator privilege is enabled.
AF_OP_COMMThe communications operator privilege is enabled.
AF_OP_SERVERThe server operator privilege is enabled.
AF_OP_ACCOUNTSThe accounts operator privilege is enabled.

{z+JK8m0
usri2_full_name
Points to a Unicode string that contains the full name of the user. This string can be a null string, or it can have any number of characters before the terminating null character.
usri2_usr_comment
Points to a Unicode string that contains a user comment. This string can be a null string, or it can have any number of characters before the terminating null character.
usri2_parms
Points to a Unicode string that is set aside for use by applications. This string can be a null string, or it can have any number of characters before the terminating null character. Microsoft products use this member to store user configuration information. Do not modify this information.
usri2_workstations
Points to a Unicode string that contains the names of workstations from which the user can log on. As many as eight workstations can be specified; the names must be separated by commas (,). A null string indicates that there is no restriction. To disable logons from all workstations to this account, set the UF_ACCOUNTDISABLE value in theusri*_flagsmember.
usri2_last_logon
Specifies when the last logon occurred. This value is stored as the number of seconds elapsed since 00:00:00, January 1, 1970. This member is ignored inNetUserAddandNetUserSetInfocalls. This member is maintained separately on each Backup Domain Controller (BDC) in the domain. To get an accurate value, each BDC in the domain must be queried, and the largest value is used.
usri2_last_logoff
Specifies when the last logoff occurred. This value is stored as the number of seconds elapsed since 00:00:00, January 1, 1970. A value of zero means that the last logoff time is unknown. This member is maintained separately on each Backup Domain Controller (BDC) in the domain. To get an accurate value, each BDC in the domain must be queried, and the largest value is used.
usri2_acct_expires
Specifies when the account will expire. This value is stored as the number of seconds elapsed since 00:00:00, January 1, 1970. A value of TIMEQ_FOREVER indicates that the account never expires.
usri2_max_storage
Specifies the maximum amount of disk space the user can use. Use the value specified in USER_MAXSTORAGE_UNLIMITED to use all available disk space.
usri2_units_per_week
Specifies the number of equal-length time units into which the week is divided in order to compute the length of the bit string in theusri2_logon_hoursmember. This value must be UNITS_PER_WEEK for LAN Manager 2.0. This element is ignored inNetUserAddandNetUserSetInfofunctions. For Windows NT services, the units must be one of the following: SAM_DAYS_PER_WEEK, SAM_HOURS_PER_WEEK, or SAM_MINUTES_PER_WEEK.
usri2_logon_hours
Points to a 21-byte (168 bits) bit string that specifies the times during which the user can log on. Each bit represents a unique hour in the week. The first bit (bit 0, word 0) is Sunday, 0:00 to 0:59; the second bit (bit 1, word 0) is Sunday, 1:00 to 1:59; and so on. A null pointer in this element forNetUserAddcalls means that there is no time restriction. A null pointer in this element forNetUserSetInfocalls means that no change is to be made.
usri2_bad_pw_count
Specifies the number of times the user tried to log on to the account using an incorrect password. A value of 0xFFFFFFFF indicates that the value is unknown. This member is ignored inNetUserAddandNetUserSetInfocalls. This member is maintained separately on each Backup Domain Controller (BDC) in the domain. To get an accurate value, each BDC in the domain must be queried, and the largest value is used.
usri2_num_logons
Counts the number of successful times the user tried to log on to this account. A value of 0xFFFFFFFF indicates that the value is unknown. This member is ignored inNetUserAddandNetUserSetInfocalls. This member is maintained separately on each Backup Domain Controller (BDC) in the domain. To get an accurate value, each BDC in the domain must be queried, and the largest value is used.
usri2_logon_server
Points to a Unicode string that contains the name of the server to which logon requests are sent. Servernames should be preceded by two backslashes (\\). When the servername is indicated by an asterisk (\\*), the logon request can be handled by any logon server. A null string indicates that requests are sent to the domain controller.

(Q`D]-Fb cVU0Windows NT:For Windows NT Servers,NetUserGetInfoandNetUserEnumreturn \\*. TheNetUserAddandNetUserSetInfofunctions ignore this member.

hQW$fLT0
usri2_country_code
Specifies the country code for the user's language of choice.
usri2_code_page
Specifies the code page for the user's language of choice.

QuickInfo

51Testing软件测试网-H SNh~+M%_Y&zb*`F

   Windows NT:Requires version 3.1 or later.
c2^9Hi$_n1d {'jb0}0   Windows:Unsupported.
[2LK Wh)a0   Windows CE:Unsupported.51Testing软件测试网E*W^6ji7`
   Header:Declared in lmaccess.h.51Testing软件测试网p_p#bV7j/l

"eY!H%h)_\b0

B5Ku]gK~ PyP0

USER_INFO_3

51Testing软件测试网J-`N;Ak|:UA

The level 3 data structure is valid only to Windows NT servers and not LAN Manager 2.xservers.51Testing软件测试网*U4u` r pq Kp$b*~5W

typedef struct _USER_INFO_3 {
    LPWSTR    usri3_name;                  //用户名
    LPWSTR    usri3_password;              //用户密码,无法直接读取密码,可以使用NetUserSetInfo设置密码
    DWORD     usri3_password_age;          //当前密码使用时间
    DWORD     usri3_priv;                  //当前帐户权限
    LPWSTR    usri3_home_dir;              //返回帐户目录,可以为空值
    LPWSTR    usri3_comment;               //说明,可以为NULL
    DWORD     usri3_flags;                 //标识
    LPWSTR    usri3_script_path;           //脚本路径
    DWORD     usri3_auth_flags;            //操作权限标识
    LPWSTR    usri3_full_name;             //帐户全称
    LPWSTR    usri3_usr_comment;           //帐户备注
    LPWSTR    usri3_parms;                 //参数,可以为NULL
    LPWSTR    usri3_workstations;          //帐户所在工作组
    DWORD     usri3_last_logon;            //上次登录时间,单位:秒,计算起始时间:1970-1-1 00:00
    DWORD     usri3_last_logoff;           //上次注销时间
    DWORD     usri3_acct_expires;          //帐户过期时间
    DWORD     usri3_max_storage;           //帐户最大可用磁盘空间
    DWORD     usri3_units_per_week;        //
    PBYTE     usri3_logon_hours;           //帐户允许登录的时间
    DWORD     usri3_bad_pw_count;          //允许密码输入错误的最多次数
    DWORD     usri3_num_logons;            //成功登录的次数
    LPWSTR    usri3_logon_server;          //
    DWORD     usri3_country_code;          //系统所使用语言的代码
    DWORD     usri3_code_page;             //
    DWORD     usri3_user_id;               //帐户相关的ID
    DWORD     usri3_primary_group_id;      //
    LPWSTR    usri3_profile;               //用户档案
    LPWSTR    usri3_home_dir_drive;        //用户目录的盘符
    DWORD     usri3_password_expired;      //用户密码过期时间
}USER_INFO_3, *PUSER_INFO_3, *LPUSER_INFO_3;

^"[m n5Ue Cq0

TAG:

 

评分:0

我来说两句

Open Toolbar