Enable 'Allow programaticclipboard access" for IE.

本文介绍了如何使用C++代码通过组策略API为当前用户启用程序化剪贴板访问,并提供了相关的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. for current user. They can simply modify belowregistry.   0=Enable, 1=Prompt

Windows Registry Editor Version 5.00

 

[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\InternetSettings\Zones\2]

"1407"=dword:00000000

 

2.Use Group Policy API for all users. Maybe the app need haveAdministrator right.

Policy settings are specified by an administrator. This is incontrast to profile settings, that are specified by a user.

Below is C++ example to enable “'Allow programaticclipboard access

 

#define   INITGUID

#include <Guiddef.h>

 

#include <Prsht.h>

#include <Gpedit.h>

 

#define GPO_IE_REG_ZONE_2_PATH _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\InternetSettings\\Zones\\2")

 

BOOL SetGroupPolicy(HKEY hKey, LPCTSTR subKey, LPCTSTRvalueName, DWORD dwType, const BYTE* szkeyValue, DWORD dwkeyValue) ;

 

 

int APIENTRY _tWinMain(HINSTANCE hInstance,

                    HINSTANCE hPrevInstance,

                    LPTSTR    lpCmdLine,

                    int       nCmdShow)

{

DWORD dwEnable = 0;

CoInitialize(NULL);

SetGroupPolicy(HKEY_LOCAL_MACHINE,GPO_IE_REG_ZONE_2_PATH,_T("1407"),REG_DWORD,NULL,dwEnable);

              ::CoUninitialize();

              return 0;

}

 

 

BOOL SetGroupPolicy(HKEY hKey, LPCTSTR subKey, LPCTSTRvalueName, DWORD dwType, const BYTE* szkeyValue, DWORD dwkeyValue)

{

    HKEY ghKey, ghSubKey, hSubKey;

    LPDWORD flag = NULL;

    IGroupPolicyObject *pGPO = NULL;

    HRESULT hr =CoCreateInstance(CLSID_GroupPolicyObject, NULL, CLSCTX_ALL,IID_IGroupPolicyObject, (LPVOID*)&pGPO);

 

    if(!SUCCEEDED(hr))

    {

       return FALSE;

    }

 

    if (RegCreateKeyEx(hKey, subKey, 0,NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hSubKey, flag) !=ERROR_SUCCESS)

    {

        return FALSE;

    }

 

    if(dwType == REG_SZ)

    {

        if(RegSetValueEx(hSubKey,valueName, 0, dwType, szkeyValue, strlen((char*)szkeyValue) + 1) !=ERROR_SUCCESS)

        {

            RegCloseKey(hSubKey);

            returnFALSE;

        }

    }

 

    else if(dwType == REG_DWORD)

    {

        if(RegSetValueEx(hSubKey,valueName, 0, dwType, (BYTE*)&dwkeyValue, sizeof(dwkeyValue)) !=ERROR_SUCCESS)

        {

            RegCloseKey(hSubKey);

           returnFALSE;        }

    }

 

    if(!SUCCEEDED(hr))

    {

      return FALSE;

    }

 

    if(pGPO->OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY)!= S_OK)

    {

          returnFALSE;

    }

 

    if(pGPO->GetRegistryKey(GPO_SECTION_USER,&ghKey)!= S_OK)

    {

          returnFALSE;

    }

 

    if(RegCreateKeyEx(ghKey, subKey, 0,NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &ghSubKey, flag) !=ERROR_SUCCESS)

    {

        RegCloseKey(ghKey);

        return FALSE;

    }

 

    if(dwType == REG_SZ)

    {

        if(RegSetValueEx(ghSubKey,valueName, 0, dwType, szkeyValue, strlen((char*)szkeyValue) + 1) !=ERROR_SUCCESS)

        {

            RegCloseKey(ghKey);

            RegCloseKey(ghSubKey);

           returnFALSE;

        }

    }

 

    else if(dwType == REG_DWORD)

    {

        if(RegSetValueEx(ghSubKey,valueName, 0, dwType, (BYTE*)&dwkeyValue, sizeof(dwkeyValue)) !=ERROR_SUCCESS)

        {

            RegCloseKey(ghKey);

            RegCloseKey(ghSubKey);

return FALSE;        }

    }

                GUID RegistryId = REGISTRY_EXTENSION_GUID;

    if(pGPO->Save(false, true,const_cast<GUID*>(&RegistryId),const_cast<GUID*>(&CLSID_GPESnapIn)) != S_OK)

    {

        RegCloseKey(ghKey);

        RegCloseKey(ghSubKey);

return FALSE;

    }

 

    pGPO->Release();

    RegCloseKey(ghKey);

    RegCloseKey(ghSubKey);

    return TRUE;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值