Call DCOM [finishing]

xiaoxiao2021-03-06  52

DCOM is dependent on the RPC service. It is a distributed remote process (process) called, calling code executing on remote hosting, using remote host system resources, so there is access to the remote host, generally to access users Should be the domain users belonging to the remote host local user or host,

and so

The first step is to register (obtained) a user with sufficient permissions in the remote host or its domain.

The second step is to use this user token to activate the remote COM server. The method is to use the CoinitializeSecurity & CocreateInstanceEx function (see the following example), after successful activation, get the proxy for the relevant request interface, at which time the agent does not access the remote server access ,

The third step is to set access to the interface agent, and the method is to use the COSetProxyBlanket function, so you can use the proxy pointer to call. See the latter example

The above is the process you want to do, as for the server side, just set the access license permission using the CoinitializeSecurity function (sometimes the client should do this, such as using the connection point), for the install server program The DCOMCFG tool is set in the registry.

CosetProxyblanket Function Call Example:

*****************************

Original example:

IrecordServerLink * PRSL = (IRECORDSERVERLINK *) MQ [0] .pitf;

HR = COSETPROXYBLANKET (PRSL, RPC_C_AUTHN_WINNT, RPC_AUTHZ_NONE, NULL, RPC_AUTHN_EVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, & CAID, EOAC_NONE); PRSL-> Methods ();

----------------------------------

Modified example:

HR = COSETPROXYBLANKET (Paccount, RPC_C_AUTHN_WINNT, RPC_AUTHZ_NON, NULL, RPC_C_AUTHN_LVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, & CAID, EOAC_NONE); Paccount-> Deposit (x);

※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※

Coinitializesecurity & CocreateInstanceEx Function Call Example:

*********************************************************** *******

Example 1:

HRESULT HR;

HR = Coinitialize (NULL);

Assert (ac));

Multi_qi qi;

Qi.piid = & IID_ICREMOTETIME;

Qi.hr = NULL;

QI.PITF = NULL;

Coauthood; AuthiDentity.user = l "administrator"; your machine's account

AuthiDentity.userLength = WCSLEN (AuthiDentity.use);

AuthiDentity.domain = NULL;

AuthiDentity.domainLength = 0;

AuthiDentity.password = L ""; password

Authidentity.passwordLength = WCSLEN (AuthiDentity.use);

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.pauthfo = null;

Servinf.pauthinfo = & authorinfo;

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 (ac));

HR = CocreateInstanceex (CLSID_CREMOTETIME, NULL, CLSCTX_REMOTE_SERVER, & Servinf, 1, & Qi);

IF (Failed (HR))

{

"CocreateInstanceex Failed");

Return False ;;

}

IF (Failed (Qi.hr))

{

Trace ("Failed to Connect To Server));

Return False ;;

}

/ / To query the interface pointer through the iUnkonwn pointer, return to the IACCount pointer

HR = punknown-> queryinterface (IID_ICREMOTETIME, (VOID **) & PIRETIME)

Example 2:

HRESULT HR = CoinitializeSecurity (NULL, -1, NULL, NULL,

RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_NONE, NULL

Coauthidentity US;

US.user = m_strname.allocsystring ();

US.UserLength = WCSLEN (US.user);

US.Password = m_StrPassword.allocsystring ();

US.PasswordLength = WCSLEN (US.Password);

US.domain = m_STRDOMAIN.Allocsystring ();

US.DomainLENGTH = WCSLEN (US.Domain); US.FLAGS = sec_winnt_auth_identity_unicode;

Coauthinfo auth;

Auth.dwauthnsvc = RPC_C_AUTHN_WINNT;

Auth.dwauthzsvc = RPC_C_AUTHZ_NONE;

Auth.PwszServerPrincName = NULL;

Auth.dwauthnlevel = RPC_C_AUTHN_LEVEL_CONNECT;

Auth.dwimpersonationLevel = RPC_C_Imp_level_impersonate;

Auth.dwcapabilities = EOAC_NONE;

Auth.PauthIdentityData = & us;

CoserverInfo Si;

Multi_qi qi;

CCOMBSTR BSTR = STRComputer;

LPWSTR Name = BSTR.M_STR;

Si.dwreserved1 = 0;

Si.pwszname = name;

Si.Pauthinfo = m_baccess? & author: null;

Si.dwreserved2 = 0;

IID IID = __UUIDOF (m_piremotecontrol);

Qi.piid = & IID;

QI.PITF = NULL;

DO

{

HR = CocreateInstanceex (__ uuidof (RemoteControl), NULL, CLSCTX_SERVER, & SI, 1, & Qi);

IF (Failed (HR) || Failed (Qi.hr))

Break;

M_PiremoteControl = (iRemoteControl *) qi.pitf;

} while (0);

-----------------------------------

Example 3:

HRESULT HR = CoinitializeSecurity (NULL, -1, NULL, NULL,

RPC_C_AUTHN_LEVEL_NONE, RPC_C_IMP_LEVEL_IDENTIFY, NULL, EOAC_NONE, NULL

Coauthidentity US;

US.user = m_strname.allocsystring ();

US.UserLength = WCSLEN (US.user);

US.Password = m_StrPassword.allocsystring ();

US.PasswordLength = WCSLEN (US.Password);

US.domain = m_STRDOMAIN.Allocsystring ();

US.DomainLength = WCSLEN (US.Domain);

US.FLAGS = SEC_WINNT_AUTH_IDENTITY_UNICODE; COAUTHINFO AUTH;

Auth.dwauthnsvc = RPC_C_AUTHN_WINNT;

Auth.dwauthzsvc = RPC_C_AUTHZ_NONE;

Auth.PwszServerPrincName = NULL;

Auth.dwauthnlevel = RPC_C_AUTHN_LEVEL_CONNECT;

Auth.dwimpersonationLevel = RPC_C_Imp_level_impersonate;

Auth.dwcapabilities = EOAC_NONE;

Auth.PauthIdentityData = & us;

Multi_qi multiqi = {& IID_IUNKNOWN, NULL, NOERROR};

CoserverInfo Si;

CCOMBSTR BSTR = STRComputer;

LPWSTR Name = BSTR.M_STR;

Si.dwreserved1 = 0;

Si.pwszname = name;

Si.Pauthinfo = m_baccess? & author: null;

Si.dwreserved2 = 0;

HR = CocreateInstanceex (__ uuidof (RemoteControl), NULL, CLSCTX_SERVER, & SI, 1, & MULTIQI);

IF (Failed (HR))

{

MessageBox ("Create an object instance failed!");

Return;

}

/ / To query the interface pointer through the iUnkonwn pointer, return to the IACCount pointer

Punknown = (iUnknown *) multiqi.pitf;

HR = punknown-> queryinterface (iid_iaccount, (void **) & paccount;

IF (Failed (HR))

{

MessageBox ("No Find Interface Pointer!");

Return False;

}

Punknown-> Release ();

转载请注明原文地址:https://www.9cbs.com/read-116699.html

New Post(0)