各位大佬,关于操作组策略的系统API有哪些?

亭台六七座 2021-07-13 21:52:59

各位大佬,关于操作组策略的系统API有哪些?

...全文
1288 1 点赞 打赏 收藏 举报
写回复
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
psbeond 2021-07-28

组策略大部分是操作注册表,不过与直接操作注册表还不完全一样,因为直接操作注册表,有时候一些设置不会马上生效,但操作组策略可以。
RefreshPolicy:刷新组策略。
下面是一段禁止设备AutoPlay的简单代码(未验证是否可行),里面有一些操作组策略的基本流程,可参考一下:
CGroupPolicy::CGroupPolicy()
{
HRESULT hr = S_OK;
::CoInitialize(NULL);
IGroupPolicyObject *p = NULL;
hr = CoCreateInstance(CLSID_GroupPolicyObject, NULL, CLSCTX_ALL, IID_IGroupPolicyObject, (LPVOID *)&p);
if (SUCCEEDED(hr))
{
DWORD dwSection = GPO_SECTION_USER;
HKEY hGPOSectionKey = NULL;
HKEY hSettingKey;
LSTATUS rStatus;
DWORD lData = 255;
hr = 0;
//hr = p->OpenDSGPO( bGPOPath, GPO_OPEN_LOAD_REGISTRY);
hr = p->OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY);
hr = p->GetRegistryKey(dwSection, &hGPOSectionKey);
long returnnum = RegOpenKeyEx(hGPOSectionKey,
L"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer", 0,
KEY_WRITE, &hSettingKey);
if (returnnum != ERROR_SUCCESS)
{
rStatus = RegCreateKeyEx(
hGPOSectionKey,
L"Software\Microsoft\Windows\CurrentVersion\Policies\Explorer",
0,
NULL,
REG_OPTION_NON_VOLATILE,
KEY_WRITE,
NULL,
&hSettingKey,
NULL);
}
rStatus = RegSetValueEx(hSettingKey, L"NoDriveTypeAutoRun",
NULL, REG_DWORD, (BYTE *)(&lData),
sizeof(DWORD));
rStatus = RegCloseKey(hSettingKey);
GUID RegistryId = REGISTRY_EXTENSION_GUID;
GUID ThisAdminToolGuid =
{
0x0F6B957E,
0x509E,
0x11D1,
{ 0xA7, 0xCC, 0x00, 0x00, 0xF8, 0x75, 0x71, 0xE3 }
};
rStatus = RegCloseKey(hGPOSectionKey);
hr = p->Save(
FALSE,
TRUE,
&RegistryId,
&ThisAdminToolGuid);
CoUninitialize();
hr = p->Release();
}

hr = S_OK;
::CoInitialize(NULL);
p = NULL;
hr = CoCreateInstance(CLSID_GroupPolicyObject, NULL, CLSCTX_ALL, IID_IGroupPolicyObject, (LPVOID *)&p);
if (SUCCEEDED(hr))
{
    DWORD dwSection = GPO_SECTION_MACHINE;
    HKEY hGPOSectionKey = NULL;
    HKEY hSettingKey;
    LSTATUS rStatus;
    DWORD lData = 255;
    hr = 0;
    //hr = p->OpenDSGPO( bGPOPath, GPO_OPEN_LOAD_REGISTRY);
    hr = p->OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY);
    hr = p->GetRegistryKey(dwSection, &hGPOSectionKey);
    long returnnum = RegOpenKeyEx(hGPOSectionKey,
            L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer", 0,
            KEY_WRITE, &hSettingKey);
    if (returnnum != ERROR_SUCCESS)
    {
        rStatus = RegCreateKeyEx(
                hGPOSectionKey,
                L"Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer",
                0,
                NULL,
                REG_OPTION_NON_VOLATILE,
                KEY_WRITE,
                NULL,
                &hSettingKey,
                NULL);
    }
    rStatus = RegSetValueEx(hSettingKey, L"NoDriveTypeAutoRun",
            NULL, REG_DWORD, (BYTE *)(&lData),
            sizeof(DWORD));
    rStatus = RegCloseKey(hSettingKey);
    GUID RegistryId = REGISTRY_EXTENSION_GUID;
    GUID ThisAdminToolGuid =
    {
        0x0F6B957E,
        0x509E,
        0x11D1,
        { 0xA7, 0xCC, 0x00, 0x00, 0xF8, 0x75, 0x71, 0xE3 }
    };
    rStatus = RegCloseKey(hGPOSectionKey);
    hr = p->Save(
            TRUE,
            TRUE,
            &RegistryId,
            &ThisAdminToolGuid);
    CoUninitialize();
    hr = p->Release();
}

}

  • 打赏
  • 举报
回复
相关推荐
发帖
Windows客户端开发
加入

7561

社区成员

Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
申请成为版主
帖子事件
创建了帖子
2021-07-13 21:52
社区公告
暂无公告