WMI獲取安全策略如:密碼複雜度、密碼鎖定閥值、密碼有效期等,相當複雜,但通過一下解決辦法,很方便的獲取到。
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;
}