DCOM is dependent on the RPC service, a distributed remote procedure (process) call, the calling code executes on the remote host, uses the remote host's system resources, and therefore has the access rights that the remote host belongs to, and generally the access user should be the remote host local user or the domain user of the host, so
The first step is to register (get) a user with sufficient privileges on the remote host or its domain.
The second step is to activate the remote COM server using this user token by using the CoInitializeSecurity & CoCreateInstanceEx function (see the example below) to successfully activate the proxy for the relevant request interface. The agent does not have permission to access the remote server at this time.
The third step is to set access permissions for the interface proxy by using the CoSetProxyBlanket function, which can then be invoked using the proxy pointer. See the article after the example
The above is the client to do processing, as for the server side, as long as the use of the CoInitializeSecurity function set access permissions on it (sometimes the client will do this, such as the use of connection points), It is also possible to use the Dcomcfg tool in the registration table for a stored server program.
CoSetProxyBlanket Function Call Example:
*******************************
Original example:
IRecordServerLink* pRSL=(IRecordServerLink*)mq[0].pItf;
hr = CoSetProxyBlanket( pRSL, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, &caid, EOAC_NONE);
pRSL->Methods();
----------------------------------
The modified example:
hr = CoSetProxyBlanket( pAccount, RPC_C_AUTHN_WINNT, RPC_C_AUTHZ_NONE, NULL,
RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, &caid, EOAC_NONE);
pAccount->Deposit(x);
※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※
CoInitializeSecurity & CoCreateInstanceEx Function Invocation Example:
*********************************************************
Example 1:
HRESULT hr;
hr = CoInitialize (NULL);
ASSERT (SUCCEEDED (HR));
Multi_qi QI;
QI.PIID = &IID_ICRemoteTime;
qi.hr = NULL;
QI.PITF = NULL;
Coauthidentity authidentity;
Authidentity. User = L "Administrator"; The account number of your machine
Authidentity. Userlength = Wcslen (authidentity. User);
Authidentity. Domain = NULL;
Authidentity. domainlength = 0;
Authidentity. Password = L ""; Password
Authidentity. Passwordlength = Wcslen (authidentity. User);
Authidentity. Flags = Sec_winnt_auth_identity_unicode;
Coauthinfo authinfo = {-1, 0, 0, Rpc_c_authn_level_default,
Rpc_c_imp_level_impersonate, &authidentity, 0};
Coserverinfo Servinf;
servinf.dwreserved1 = NULL;
Servinf.dwreserved2 = NULL;
Servinf.pauthinfo = NULL;
Servinf.pauthinfo = &authinfo;
Uses_conversion;
Servinf.pwszname = L "127.0.0.1";
hr = CoInitializeSecurity (null,-1, NULL, NULL,
Rpc_c_authn_level_none, rpc_c_imp_level_identify, NULL, Eoac_access_control, NULL);
ASSERT (SUCCEEDED (HR));
hr = CoCreateInstanceEx (Clsid_cremotetime, NULL, Clsctx_remote_server, &servinf, 1, &qi);
if (FAILED (HR))
{
TRACE (_t ("CoCreateInstanceEx failed"));
return false;;;
}
if (FAILED (qi.hr))
{
TRACE (_t ("Failed to connect to server");
return false;;;
}
IUNKONWN pointer to query interface pointer, return iaccount pointer
hr = Punknown->queryinterface (Iid_icremotetime, (void**) &piretime)