QueryInterface fails with E_ACCESSDENIED

2020-07-20 03:15发布

The following method is a DCOM server method. The COM client and server is running in different WinXP machines. The COM client calls RegisterClient method to register callback interface. The problem is QueryInterface method fails with error code E_ACCESSDENIED. What could be the reason for the issue?

STDMETHODIMP CGEMExtension::RegisterClient(IUnknown** ppGEMExtensionEvents, int* nClientId, int* nResult)
{
    HRESULT  hRes = (*ppGEMExtensionEvents)->QueryInterface(IID_IGEMExtension,(void**)&pUnknown);
    return hRes;
}

标签: c++ com dcom
3条回答
聊天终结者
2楼-- · 2020-07-20 04:05

I give you my experience even if it may not apply directly to your specific case.

On Windows 7 at 64bit I have an exe compiled with x64 and a dll compiled at 32 bit.

A COM object lives inside the dll.

The exe (launched by the "normal" user) creates the COM object (on the same computer) asking for IUnknown and the creation is successful. Then the exe asks for a different interface through QueryInterface and it fails with E_ACCESSDENIED.

If I launch the exe "as administrator" then the QueryInterface will return with S_OK.

I did not investigate further, I suspect there is some policy about the 32 bit - 64 bit interaction.

查看更多
放荡不羁爱自由
3楼-- · 2020-07-20 04:16

This might be because the correct permissions is wrong on the other computer. Simplest way to check this is to turn on logging with secpol (Local Policies, Audit policy, turn on logging of logon events and object access) then you can see if you are trying to access the other machine.

If you are just testing then I would suggest to use the setting "run as interactive user" on the com object in component services and make sure that you have the same user with the same password on both machines. Then you must be running as the common user on the client machine. Spesifically setting the user to the common user is also possible.

As a general advice to debugging DCOM connectivity: Turn off all firewalls and such to make sure that the connection is working, then turn on security measures one by one, making sure that you leave the correct ports open and that the correct users have the correct permissions.

查看更多
The star\"
4楼-- · 2020-07-20 04:17

When you get an E_ACCESSDENIED, it means you have a permissions problem (don't waist your time on firewalls or registrations - the former will raise errors telling you the service is not available, and the latter will tell you the class is not registered or so). COM relies on Windows permissions, so this is what you should focus on.

In your case, if I understand the case correctly, the server actually calls the client, in order to get the right interface. For that, the user running the server should have the right permissions on the client side. A few suggestions:

  1. As daramarak suggests, have the server and the client use the same domain user, or the same local user with the same password.
  2. On the client, set this setting to "classic".
  3. Give the server's user, if known to the client, additional permissions using DCOMCNFG.
查看更多
登录 后发表回答