c++ - 密码策略 Windows API

标签 c++ .net winapi policy

是否有任何 API 可用于本地和/或全局密码策略(读/写策略设置)?

我发现有一个windows命令:

net accounts

它使用什么 API 来读取设置?是否可以在管理员权限下以编程方式更改设置?

最佳答案

使用可以使用netapi32.lib中的NetUserModalsGet()函数。

请参阅 https://msdn.microsoft.com/en-us/library/aa370656(VS.85).aspx 中的示例

NetUserModalsGet

struct USER_MODALS_INFO_0
{
    DWORD usrmod0_min_passwd_len;
    DWORD usrmod0_max_passwd_age;
    DWORD usrmod0_min_passwd_age
    DWORD usrmod0_force_logoff; 
    DWORD usrmod0_password_hist_len;
}
PUSER_MODALS_INFO_0 = ^USER_MODALS_INFO_0;    

PUSER_MODALS_INFO_0 info0;

NET_API_STATUS res = NetUserModalsGet(nil, 0,  out info0);

if (res <> NERR_Success)
   RaiseWin32Error(res);
try
   //Specifies the minimum allowable password length. 
   //Valid values for this element are zero through PWLEN.
   Log(info0.usrmod0_min_passwd_len);

   //Specifies, in seconds, the maximum allowable password age. 
   //A value of TIMEQ_FOREVER indicates that the password never expires. 
   //The minimum valid value for this element is ONE_DAY. 
   //The value specified must be greater than or equal to the value for the usrmod0_min_passwd_age member.
   Log(info0.usrmod0_max_passwd_age);

   //Specifies the minimum number of seconds that can elapse between the time
   //a password changes and when it can be changed again. 
   //A value of zero indicates that no delay is required between password updates. 
   //The value specified must be less than or equal to the value for the usrmod0_max_passwd_age member.
   Log(info0.usrmod0_min_passwd_age);

   //Specifies, in seconds, the amount of time between the end of the valid
   // logon time and the time when the user is forced to log off the network. 
   //A value of TIMEQ_FOREVER indicates that the user is never forced to log off. 
   //A value of zero indicates that the user will be forced to log off immediately when the valid logon time expires.
   Log(info0.usrmod0_force_logoff);

   //Specifies the length of password hi'+'story maintained. 
   //A new password cannot match any of the previous usrmod0_password_hist_len passwords. 
   //Valid values for this element are zero through DEF_MAX_PWHIST
   Log(info0.usrmod0_password_hist_len);
finally
   NetApiBufferFree(info0);
end;

关于c++ - 密码策略 Windows API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13376262/

相关文章:

delphi - 在 Delphi 7 中向 TfontDialog 添加自定义颜色

c++ - 无法在C++中打印指针的地址

c++ - 使用 QT 和参数在 SQLite 数据库中插入日期时间

c++ - 程序崩溃顺序排序程序

.net - 如何在 Nginx 服务器中将 ASP.NET Core Web API dll 文件作为服务运行?

c++ - 使用 WM_GETTEXT 获取窗口标题

c++ - C++中的QuickSort,遇到麻烦

.net - 有没有办法检测 "almost"远程桌面断开连接(即短暂的高延迟)?

c# - 列出操作复杂度

c++ - 在 VC++ 中使用 GetOpenFileName() API 打开文件夹而不是文件