WMI in VC++, Access Denied
-
Hi all, I am trying to use WMI (just learning) in VC++. However, there seems to be a problem when it comes to connecting to a Remote Host . Which works very well on the local computer. The machine I am trying to connect has Win2K on it and I have WinXP installed on my machine. Now, when I try to execute the following code snippet, it gives me an Access Denied error. Also when I try to query the same through WBEMTEST.exe, everything work fine. Here is the code snippet : - // Initialize Security hrRetVal = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, 0); // CreateInstance hrRetVal = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IWbemLocator, (void **) &pWbemLocator); BSTR bsNameSpace = SysAllocString(L"//RemoteComputer/root/cimv2"); BSTR bsUserName = SysAllocString(L"abc"); BSTR bsPassword = SysAllocString(L"123"); // Connect to the Server hrRetVal = pWbemLocator->ConnectServer(bsNameSpace, bsUserName, bsPassword, 0, NULL, NULL, 0, &pWbemServices); // Query the Proxy Blanket for Authorization Level hrRetVal = CoQueryProxyBlanket(pWbemServices, NULL, NULL, NULL, &dwAuthLevel, NULL, NULL, NULL); // Set the Proxy Blanket to the Authorization Level hrRetVal = CoSetProxyBlanket(pWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NAME, NULL, dwAuthLevel, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE); // Execute Query --> Access Denied hrRetVal = pWbemServices->ExecQuery(L"WQL", L"Select * from Win32_Service",
-
Hi all, I am trying to use WMI (just learning) in VC++. However, there seems to be a problem when it comes to connecting to a Remote Host . Which works very well on the local computer. The machine I am trying to connect has Win2K on it and I have WinXP installed on my machine. Now, when I try to execute the following code snippet, it gives me an Access Denied error. Also when I try to query the same through WBEMTEST.exe, everything work fine. Here is the code snippet : - // Initialize Security hrRetVal = CoInitializeSecurity(NULL, -1, NULL, NULL, RPC_C_AUTHN_LEVEL_CALL, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, 0); // CreateInstance hrRetVal = CoCreateInstance(CLSID_WbemLocator, NULL, CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER, IID_IWbemLocator, (void **) &pWbemLocator); BSTR bsNameSpace = SysAllocString(L"//RemoteComputer/root/cimv2"); BSTR bsUserName = SysAllocString(L"abc"); BSTR bsPassword = SysAllocString(L"123"); // Connect to the Server hrRetVal = pWbemLocator->ConnectServer(bsNameSpace, bsUserName, bsPassword, 0, NULL, NULL, 0, &pWbemServices); // Query the Proxy Blanket for Authorization Level hrRetVal = CoQueryProxyBlanket(pWbemServices, NULL, NULL, NULL, &dwAuthLevel, NULL, NULL, NULL); // Set the Proxy Blanket to the Authorization Level hrRetVal = CoSetProxyBlanket(pWbemServices, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NAME, NULL, dwAuthLevel, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE); // Execute Query --> Access Denied hrRetVal = pWbemServices->ExecQuery(L"WQL", L"Select * from Win32_Service",