WMI获取安全策略如:密码复杂度、密码锁定阀值、密码有效期等,相当复杂,但通过以下解决办法,很方便的获取到:
1、现在以管理员模式打开的cmd命令行键入看下效果 键入命令为
secedit /export /cfg luan.inf > 0 & type luan.inf | findstr /R /i "^min ^max ^pass ^lock"
得到如下图:
以同样的办法可获取到组策略相关的参数如此链接;https://blog.csdn.net/irizhao/article/details/78481529?utm_source=blogxgwz3
2、实际代码中用c++函数调用如下:
int main()
{
string command_rd = "secedit /export /cfg luan.inf > 0 & type luan.inf | findstr /R /i \"^min ^max ^pass ^lock\"";
system(command_rd.c_str());
}
方法二:以下函数等同于system,但很方便的将获取返回值类型为string。
string getCmdResult(const string &strCmd)
{
char buf[10240] = { 0 };
FILE *pf = NULL;
if ((pf = _popen(strCmd.c_str(), "r")) == NULL)
{
return "";
}
string strResult;
while (fgets(buf, sizeof buf, pf))
{
strResult += buf;
}
_pclose(pf);
unsigned int iSize = strResult.size();
if (iSize > 0 && strResult[iSize - 1] == '\n')
{
strResult = strResult.substr(0, iSize - 1);
}
return strResult;
}
int main()
{
string command_rd = "secedit /export /cfg luan.inf > 0 & type luan.inf | findstr /R /i \"^min ^max ^pass ^lock\"";
string str;
str = getCmdResult(command_rd);
cout << str << endl;
}