通过GPO禁用Aeroshaake最小化

问题描述 投票:0回答:1

我正在尝试仅禁用Aeroshake最小化鼠标手势。问了一个问题How to disable Aero Shake minimize only on Windows 7,但没有答案。因此,我继续进行挖掘,并通过更新用户组策略找到了另一个解决方案。

void aeroshake(DWORD action)
{
    HRESULT hr;
    IGroupPolicyObject* pLGPO;
    HKEY machine_key, dsrkey;
    LSTATUS sdf, ds, rStatus;
    GUID RegistryId = REGISTRY_EXTENSION_GUID;
    GUID ThisAdminToolGuid =
        /*{ CLSID_PolicySnapinUser/* */
    {
        0x0F6B957E,
        0x509E,
        0x11D1,
    { 0xA7, 0xCC, 0x00, 0x00, 0xF8, 0x75, 0x71, 0xE3 }
    };

    const IID my_IID_IGroupPolicyObject =
    { 0xea502723, 0xa23d, 0x11d1,{ 0xa7, 0xd3, 0x0, 0x0, 0xf8, 0x75, 0x71, 0xe3 } };
    const IID my_CLSID_GroupPolicyObject =
    { 0xea502722, 0xa23d, 0x11d1,{ 0xa7, 0xd3, 0x0, 0x0, 0xf8, 0x75, 0x71, 0xe3 } };
    GUID ext_guid = REGISTRY_EXTENSION_GUID;

    // This next one can be any GUID you want
    GUID snap_guid = { 0x3d271cfc, 0x2bc6, 0x4ac2,{ 0xb6, 0x33, 0x3b, 0xdf, 0xf5, 0xbd, 0xab, 0x2a } };

    // Create an instance of the IGroupPolicyObject class
    CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    CoCreateInstance(my_CLSID_GroupPolicyObject, NULL, CLSCTX_INPROC_SERVER,
        my_IID_IGroupPolicyObject, (LPVOID*)&pLGPO);

    // We need the machine LGPO (if C++, no need to go through the lpVtbl table)
    hr = pLGPO->OpenLocalMachineGPO(GPO_OPEN_LOAD_REGISTRY);
    if (hr != S_OK) {
        goto release;
    }

    hr = pLGPO->GetRegistryKey(GPO_SECTION_USER, &machine_key);
    if (hr != S_OK) {
        goto close;
    }

    // create key for disable Aeroshake minimise
    sdf = RegCreateKeyEx(machine_key, TEXT("Software\\Policies\\Microsoft\\Windows\\Desktop\\NoWindowMinimizingShortcuts"),
        0, NULL, 0, KEY_SET_VALUE | KEY_QUERY_VALUE, NULL, &dsrkey, NULL);

    // Create the value
    ds = RegSetKeyValue(dsrkey, NULL, TEXT("NoWindowMinimizingShortcuts"), REG_DWORD, &action, sizeof(action));
    RegCloseKey(dsrkey);

    // Apply policy and free resources
    pLGPO->Save( TRUE, TRUE, &ext_guid, &snap_guid);
    rStatus = RegCloseKey(machine_key);

    // Write the GPO back to the directory
    hr = pLGPO->Save(
        FALSE,
        TRUE,
        &RegistryId,
        &ThisAdminToolGuid);

close:
    RegCloseKey(machine_key);

release:
    pLGPO->Release();
}

这看起来像是正确的方法,但是我对OpenLocalMachineGPO有疑问,它总是返回E_ACCESSDENIED。可以排序而无需以管理员身份运行。同样,当代码以Admin身份运行时,它仍然不会更改所需的策略。

c++ winapi aero gpo
1个回答
0
投票

[E_ACCESSDENIED表示没有访问权限,当然您需要足够的权限才能修改GPO。

此外,键值NoWindowMinimizingShortcuts在子键Software\\Policies\\Microsoft\\Windows\\Explorer

sdf = RegCreateKeyEx(machine_key, TEXT("Software\\Policies\\Microsoft\\Windows\\Explorer"),
        0, NULL, 0, KEY_SET_VALUE | KEY_QUERY_VALUE, NULL, &dsrkey, NULL);

您需要重新启动或至少注销,然后登录才能生效。(即使您直接在GPO中进行修改)

然后更改将更新为HKEY_CURRENT_USER\Software\Policies\Microsoft\Windows\Explorer

NoWindowMinimizingShortcuts = 0x00000001

当然,您也可以直接修改此密钥。(如果没有,则需要首先创建它)

void aeroshake(DWORD action)
{
    // create key for disable Aeroshake minimise
    HKEY hKeyRoot, dsrkey;
    LSTATUS sdf = RegOpenKey(HKEY_CURRENT_USER, TEXT("Software\\Policies\\Microsoft\\Windows"), &hKeyRoot);
    sdf = RegCreateKey(hKeyRoot, TEXT("Explorer"), &dsrkey);
    // Create the value
    sdf = RegSetKeyValue(dsrkey, NULL, TEXT("NoWindowMinimizingShortcuts"), REG_DWORD, &action, sizeof(action));
    RegCloseKey(dsrkey);
}
© www.soinside.com 2019 - 2024. All rights reserved.