0

我正在使用 IGroupPolicyObject 接口打开注册表项。我使用 GPO_SECTION_MACHINE 加载了注册表,但是当我使用 RegOpenKeyEx 打开注册表项“SOFTWARE\Microsoft\Windows NT\CurrentVersion\SecEdit\Reg Values”时,返回错误代码 2。我正在以管理员身份运行我的 exe(内置于 Visual Studio 2008,c++)。我想知道如何打开上述密钥?任何形式的帮助将不胜感激。

下面是我用来打开密钥的代码。

GUID RegistryId = REGISTRY_EXTENSION_GUID;
GUID ThisAdminToolGuid =
{
    0x0F6B957E,
    0x509E,
    0x11D1,
    {0xA7, 0xCC, 0x00, 0x00, 0xF8, 0x75, 0x71, 0xE3}
};

hres = CoCreateInstance(
                    CLSID_GroupPolicyObject,
                    NULL,
                    CLSCTX_INPROC_SERVER,
                    IID_IGroupPolicyObject,
                    (LPVOID*)&pIGroupPolicyObject
                    );
if (S_OK != hres || NULL == pIGroupPolicyObject)
{
    _tprintf(_T("\n hres != S_OK"));
    return FALSE;
}

hres = pIGroupPolicyObject->OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY);
if (FAILED(hres))
{

    _tprintf(_T("\n hres != S_OK"));
    return FALSE;
}

hres = pIGroupPolicyObject->GetRegistryKey(GPO_SECTION_MACHINE, &hGPOSectionUserKey);
if (FAILED(hres) || NULL == hGPOSectionUserKey)
{

    _tprintf(_T("\n hres != S_OK"));
    return FALSE;
}
lRetVal = RegOpenKeyEx(hGPOSectionUserKey, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SeCEdit\\Reg Values\\MACHINE/System/CurrentControlSet/Services/LanManServer/Parameters/NullSessionShares"), 0, KEY_READ, &hSettingUserKey);
4

1 回答 1

0

调用RegOpenKeyEx返回 2,即ERROR_FILE_NOT_FOUND. 这意味着您提供的路径不存在。哪个是对的。您提供:"HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SeCEdit\\Reg Values\\MACHINE/System/CurrentControlSet/Services/LanManServer/Parameters/NullSessionShares".

确保该路径不存在。你应该通过:"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\SeCEdit\\Reg Values".

于 2014-09-09T11:29:15.623 回答