0

リモート オブジェクトのインスタンス化にうんざりしています。

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 を使用していません。匿名で電話してみようかな。

4

2 に答える 2

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
于 2012-07-23T14:49:28.233 に答える
0

Windows Server 2003で同じコードが正常に実行されているときに、エラークラスがXPマシンに登録されていません

  IGPM *pGPM = NULL; 
 hr = CoCreateInstance(CLSID_GPM, NULL, CLSCTX_INPROC_SERVER, IID_IGPM , (LPVOID*)&pGPM);
于 2013-05-03T05:06:41.670 に答える