Share via


Unable to call "CoInitializeSecurity"

Question

Monday, December 11, 2006 8:02 AM

Hi Everyone.

 

I'm in trouble about DCOM server & client system in Vista.

When the Client try to call a procedure in a remote DCOM server,

CoInitializeSecurity(client side) is failed by "RPC_E_TOO_LATE".

By MSDN document it occurs when CoInitializeSecurity() has been

already called. But in this case it had never been called in a same process.

I have this problem only in Vista OS. It worked correctly in XP and 2003ServerR2.

If anybody have a good suggestion, please tell me.

 

Kohei.

All replies (2)

Monday, December 11, 2006 10:33 PM ✅Answered

DCOM, is not my area of expertise, but you are correct MSDN says "Security must be initialized before any interfaces are marshaled or unmarshaled. It cannot be changed once it is initialized." Also says that its a result of "CoInitializeSecurity has already been called."

CoInitializedSecuirty can be called on the client, the server, or both and should be OK. Just curious are  you calling it on both?

MSDN also says
"For legacy applications and other applications that do not explicitly call CoInitializeSecurity, COM calls this function implicitly with values from the registry. If you set processwide security using the registry and then call CoInitializeSecurity, the AppID registry values will be ignored and the CoInitializeSecurity values will be used."

Is it possible that CoInitialized is getting called automatically and its using registry settings? Have you tried you code with out calling CoInitializeSecurity, this would indicate that it may have already been automatically called.

One last question I have is: Do you know the permissions at which your Client and Server are running as?


Tuesday, December 12, 2006 1:31 AM ✅Answered

Dear Mr.Lundt

I really appreciate your quick reply.

>CoInitializedSecuirty can be called on the client, the server,
>or both and should be OK. Just curious are  you calling it on both?

In this system, CoInitializeSecurity is called only in a client.
The program call this API to set the authentic information which is
not depending on who execute(or logged in), to connect DCOM server.

>Is it possible that CoInitialized is getting called automatically
>and its using registry settings? Have you tried you code with out calling
>CoInitializeSecurity, this would indicate that it may have already been
>automatically called.

Your suggestion is interesting. Because before calling CoInitializeSecurity,
the program called CoCreateInstanceEx once to try to connect DCOM server
in a default security settings. The detail of this sequence is as follows.

hr = CoCreateInstanceEx(...)
if(FAILED(hr){

 ... security settings for SOLE_AUTHENTICATION_INFOs ...

 CoInitializeSecurity(...)
 CoCreateInstanceEx(...)
}

If CoInitializeSecurity called automatically by first calling CoCreateInstanceEx(),
it would be cause of error RPC_E_TOO_LATE.
But if the cause of error is exactly this, I wonder why this program worked
in XP and 2003ServerR2 without any errors ?
Is there any changes at CoInitializeSecurity API in Vista?

>Do you know the permissions at which your Client and Server are running as?

DCOM server running as Administrator of local machine which DCOM server is installed.
Client running as Administrator of local machine.
And I tried privilege elevation for client program (by manifest and "Run as" settings in GUI),
but it appeared same error.

First I try to make debug version of this program which is without calling
CoInitializeSecurity and make sure that CoInitializeSecurity is called automatically or not.

Thanks.