c++ - 如何恢复注册表项的有效权限?C++
问题描述
我想检索给定注册表项的有效权限作为参数。我在 Windows 下使用现有的注册表项进行测试。为此,我使用 CreateFile、GetSecurityInfo 和 GetEffectiveRightsFromAclA 方法。我想知道这是否是正确的方法,因为 CreateFile 方法有一个错误,它返回 INVALID_HANDLE_VALUE。此外,对于 GetEffectiveRightsFromAclA 方法,我不明白我必须在 TRUSTEE_A 中输入哪个参数?
LPCWSTR lpwRegistryKey = L"HKEY_CLASSES_ROOT\\.acc\\OpenWithProgids\\WMP11.AssocFile.ADTS";
HANDLE handleKey;
handleKey = CreateFile(lpwRegistryKey, GENERIC_READ, FILE_SHARED_READ, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
if(handleKey == INVALID_HANDLE_VALUE)
{
//qDebug()<<"error";
}
//Here is an user SID
PSID pUserSid;
QString sSid("S-4-5-12");
BOOL resultSidConvert = ConvertStringSidToSidA(sSid.toStdString().c_str(), &pUserSid);
//Here success
if(resultSidConvert != 0)
{
PACL pDacl;
PSECURITY_DESCRIPTOR pSecurityDescriptor;
DWORD dwResultSecurity = GetSecurityInfo(handleKey, SE_REGISTRY_KEY, DACL_SECURITY_INFORMATION, nullptr, &pUserSid, &pDacl, nullptr, &pSecurityDescritptor);
if(dwResultSecurity == ERROR_SUCCESS)
{
ACCESS_MASK pAccessMask;
TRUSTEE_A pTrustee; //How should I initialize pTrustee?
DWORD dwEffectiveRights = (GetEffectiveRightsFromAclA(pDacl, &pTrustee, &pAccessMask);
if(dwEffectiveRights == ERROR_SUCCESS)
{
if((pAccessMask & DELETE) == DELETE)
{
qDebug()<<"Delete";
}
if((pAccessMask & GENERIC_READ) == GENERIC_READ)
{
qDebug()<<"READ";
}
//etc ..........
}
}
}
解决方案
注册表项不是文件!
不要使用 CreateFile。请改用 RegOpenKeyEx。首先,您必须以管理员身份运行应用程序。
然后,您可以成功打开密钥。之后,看看RegGetKeySecurity
功能。
推荐阅读
- mysql - 错误代码:1136。列数与第 1 行的值计数不匹配,我找不到错误
- facebook - 如何从 Header Drupal 8 中删除 Facebook Pixel
- python - 抽象通用外壳设置功能的 Pythonic 方法
- batch-file - 从找到的最后一个分隔符中排除文本
- javascript - plotly 和 javascript 的主要和次要标记
- java - 弹性搜索查询
- apache-kafka - 如何将流云流与自定义生产者和消费者连接
- javascript - 使用 ajax 在引导轮播上附加数据
- html - React JS MERN堆栈项目中的黑色空白视频错误
- python - 在QGIS中检测迭代中最后一项的正确方法是什么