Native C++ code:
int main()
{
auto hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
COSERVERINFO server = {0, L"Win7x64", nullptr, 0};
MULTI_QI qi = {&IID_XXXService, nullptr, 0};
hr = CoCreateInstanceEx(CLSID_XXXService, nullptr, CLSCTX_REMOTE_SERVER, &server, 1, &qi);
}
Succeeds, with any threading model. With or without a call to CoInitializeSecurity
.
But when trying to instantiate same object from a .NET/C#, it always fails with 0x80070005
:
static void Main(string[] args)
{
var machineName = "Win7x64";
try
{
Type dcomType = Type.GetTypeFromCLSID(typeof(XXXService).GUID, machineName, false);
object dcomObj = Activator.CreateInstance(dcomType);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
I have tried the latter with CoInitializeSecurity
(DllImported), with MTA and STA thread attribute, with UAC elevated process, but it always fails. If machineName
is for current machine, it works (yes, current development machine has same COM interface, and class registered).
EDIT: In order to successfully call CoInitializeSecurity
, the setting 'Enable the Visual Studio hosting process' must be disabled. Still then, CreateInstance
fails.
With native code, it always works. With managed code, it never works. What could be done?
EDIT2: COM security on remote machine:
- Access Permissions (Limits): Everyone, as well as ANONYMOUS LOGON (among other common) - Full access.
- Access Permissions (Default): SELF, SYSTEM, ANONYMOUS LOGON - Full access to all.
- Launch & Activation (Limits): Everyone, DCOM Users, ANONYMOUS LOGON (among other common) - Full access.
- Launch & Activation Permissions (Default): SYSTEM, NETWORK, ANONYMOUS LOGON, INTERACTIVE - Full access to all.