设置wcm_global_property_minimize_policy时WINAPI WcmSetProperty失败

时间:2014-02-05 17:27:32

标签: windows

我正在尝试通过WcmSetProperty API设置wcm_global_property_minimize_policy。由于某种原因,调用返回错误87(无效参数)。奇怪的是我可以通过WcmQueryProperty成功查询此策略。我试图在Windows 8 SDK中找到示例代码,但AFAIL没有更改全局属性的示例。

有人可以通过以下代码告诉我我的错误吗?

void __cdecl main()
{
 DWORD dwRetCode = NO_ERROR;
 DWORD dwSize = 0;
 WCM_POLICY_VALUE policyVal; 
 WCM_POLICY_VALUE *outVal;

 /* Disable Minimize Connections */
 policyVal.fIsGroupPolicy = false;
 policyVal.fValue = false;

 dwSize = sizeof(policyVal);

 wprintf(L"Disabling global property - minimize connections... dwSize: %u\n", dwSize);

 dwRetCode = WcmSetProperty(NULL, NULL, wcm_global_property_minimize_policy, NULL, dwSize, (PBYTE)&policyVal);

 if (dwRetCode == ERROR_SUCCESS) {
  wprintf(L"Disable global property minimize connections is success\n");
 }
 else {
  wprintf(L"Disable global property minimize connections failed\n");
  wprintf(L"Error code: %u\n", dwRetCode);
 }

 dwRetCode = WcmQueryProperty(NULL, NULL, wcm_global_property_minimize_policy, NULL, &dwSize, (PBYTE *)&outVal);

 if ((dwRetCode == ERROR_SUCCESS) /*&& (p2Data != NULL)*/) {
  wprintf(L"Global property minimize policy is: %d.%d with size %d\n", outVal->fIsGroupPolicy, outVal->fValue, dwSize);
 }
 else {
  wprintf(L"Error in querying property - minimize policy \n");
  wprintf(L"Error code: %u\n", dwRetCode);
 }
}

另外,如果我通过WcmSetProperty()更改wcm_global_property_minimize_policy,这是否需要系统重启才能使更改的设置生效?

谢谢!

1 个答案:

答案 0 :(得分:1)

以下是来自MSDN论坛的回复:

“调用WcmSetProperty时,文档指定存储在pbData中的数据类型应为WCM_POLICY_VALUE。

这似乎是文档中的错误。要设置wcm_global_property_minimize_policy,请将pbData设置为BOOL类型,并且调用应该成功。“