任何人都让DCOM在Windows 7中使用CoCreateInstanceEx

时间:2012-07-22 22:14:50

标签: com ole dcom

我厌倦了尝试实例化一个远程对象。

使用dcomcnfg,对所有Windows 7,相同的工作组PC启用访问权限。

CoInitializeEx(0,COINIT_APARTMENTTHREADED);
CoInitializeSecurity(0, -1, NULL, NULL,RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, NULL, EOAC_NONE, NULL);
COAUTHINFO ca = {0};
ca.dwAuthnSvc = RPC_C_AUTHN_WINNT;
ca.dwAuthzSvc = RPC_C_AUTHZ_NONE;
ca.dwAuthnLevel = RPC_C_AUTHN_LEVEL_DEFAULT;
ca.dwImpersonationLevel = RPC_C_IMP_LEVEL_IMPERSONATE;
COAUTHIDENTITY id = {0};
ca.pAuthIdentityData = &id;
id.User = (USHORT*)<username>;
id.UserLength = length;
id.Password = (USHORT*)<password>;
id.PasswordLength = pwdlength;
id.Domain = (USHORT*)L"WORKGROUP";
id.DomainLength = 9;
id.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;

COSERVERINFO c = {0};
c.pwszName = L"192.168.10.3";
c.pAuthInfo = &ca;
MULTI_QI res = {0};
res.pIID = &TheIID;
HRESULT hr = CoCreateInstanceEx(TheCLSID,0,CLSCTX_REMOTE_SERVER,&c,1,&res);

始终是E_ACCESSDENIED。顺便说一句,这个示例(http://support.microsoft.com/kb/259011)的工作原理。但我找不到它的来源。

服务器还调用具有相同级别的CoInitializeSecurity()。

当定位Windows XP计算机时,CoCreateInstanceEx()返回S_OK,但未创建服务器。在定位Windows 7时,E_ACCESSDENIED。

任何线索? 此外,工作样品不使用U + P.也许我应该尝试一个匿名电话?

2 个答案:

答案 0 :(得分:0)

我有它的工作......

我对您的代码示例有一些观察:

  • 在CoInitializeSecurity中对SOLE_AUTHENTICATION_LIST使用NULL;我使用与CoCreateInstanceEx

  • 相同的凭据填写
  • 您使用RPC_C_AUTHN_LEVEL_DEFAULT;我使用RPC_C_AUTHN_LEVEL_CONNECT

希望这会有所帮助。我可以建议您将DCOM作为标签添加到您的问题中...这将向您显示DCOM相关问题。这也帮助了我。

    SEC_WINNT_AUTH_IDENTITY authIdent;
    std::wstring domain = string_cast<std::wstring>(commandLineOptions["domain"].as<std::string>());
    std::wstring username = string_cast<std::wstring>(commandLineOptions["username"].as<std::string>());
    std::wstring password = string_cast<std::wstring>(commandLineOptions["password"].as<std::string>());
    authIdent.Domain = reinterpret_cast<unsigned short*>(const_cast<wchar_t*>(domain.c_str()));
    authIdent.DomainLength = wcslen(reinterpret_cast<const wchar_t*>(authIdent.Domain));
    authIdent.User = reinterpret_cast<unsigned short*>(const_cast<wchar_t*>(username.c_str()));
    authIdent.UserLength = wcslen(reinterpret_cast<const wchar_t*>(authIdent.User));
    authIdent.Password = reinterpret_cast<unsigned short*>(const_cast<wchar_t*>(password.c_str()));
    authIdent.PasswordLength = wcslen(reinterpret_cast<const wchar_t*>(authIdent.Password));
    authIdent.Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE;

    /*
    SOLE_AUTHENTICATION_INFO authInfo[2];
    authInfo[0].dwAuthnSvc = RPC_C_AUTHN_WINNT;
    authInfo[0].dwAuthzSvc = RPC_C_AUTHZ_NONE;
    authInfo[0].pAuthInfo = &authIdent;

    authInfo[1].dwAuthnSvc = RPC_C_AUTHN_GSS_KERBEROS;
    authInfo[1].dwAuthzSvc = RPC_C_AUTHZ_NONE;
    authInfo[1].pAuthInfo = &authIdent;

    SOLE_AUTHENTICATION_LIST authList;
    authList.cAuthInfo = 2;
    authList.aAuthInfo = authInfo;
    */

    SOLE_AUTHENTICATION_INFO authInfo[1];
    authInfo[0].dwAuthnSvc = RPC_C_AUTHN_WINNT;
    authInfo[0].dwAuthzSvc = RPC_C_AUTHZ_NONE;
    authInfo[0].pAuthInfo = &authIdent;

    SOLE_AUTHENTICATION_LIST authList;
    authList.cAuthInfo = 1;
    authList.aAuthInfo = authInfo;


    HRESULT hr = CoInitializeSecurity(
        nullptr,                     // pVoid
        -1,                          // cAuthSvc
        nullptr,                     // asAuthSvc
        nullptr,                     // pReserved1,
        RPC_C_AUTHN_LEVEL_CONNECT,   // dwAuthnLevel,
        RPC_C_IMP_LEVEL_IMPERSONATE, // dwImpLevel,
        &authList,                   // pAuthList,
        EOAC_NONE,                   // dwCapabilities,
        nullptr);                    // pReserved3

答案 1 :(得分:0)

我的错误类没有在我的xp机器上注册,而相同的代码在Windows Server 2003上运行正常

  IGPM *pGPM = NULL; 
 hr = CoCreateInstance(CLSID_GPM, NULL, CLSCTX_INPROC_SERVER, IID_IGPM , (LPVOID*)&pGPM);
相关问题