Skip to main content
MI_Context_GetLocalSession function

Gets the local session ( MI_Session) which allows the provider to perform CIM operations against the local server hosting the provider.


 MI_INLINE MI_Result MI_Context_GetLocalSession(
  _In_  const MI_Context *context,
  _Out_       MI_Session *session


context [in]

A pointer to the request context.

session [out]

A pointer to the returned MI_Session object. This session must not be closed.

Return value

A value of the MI_Result enumeration that specifies the function return code. This can be one of the following codes.


The operation succeeded.


There is not enough memory to complete the request.


One or more parameters passed to the function were not valid.


A failure not covered by other MI_Result error codes.


Access to a CIM resource is not available to the client.


This session is pre-instantiated and has the lifetime of the context from which the session was obtained. The provider must not close this session because its lifetime is bound to the context.

The provider should call this function rather than creating a new session through the MI_Application_NewSession function, because some optimizations may be possible for talking to the CIM server.

The security context used to call the MI_Context_GetLocalSession function should be the same identity used communicate back to the server through the MI_Session_* operation functions. Do not cache these sessions outside the current operation. The provider calls this method multiple times within an operation under different identities, in which case the retrieved session should also be used with the same identity. Any operations on the session should always be the same identity that the user retrieved for the local session, or else the operation could fail with the MI_RESULT_ACCESS_DENIED return code.


Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012


Windows Management Framework 3.0 on Windows Server 2008 R2 with SP1, Windows 7 with SP1, and Windows Server 2008 with SP2