Platform SDK: Transaction Server

IObjectContext::IsCallerInRole, IObjectContext::IsSecurityEnabled Methods Example

[This product will work only on Windows NT 4.0 versions and earlier. For Windows 2000 and later, see COM+ (Component Services).]

#include <mtx.h>

IObjectContext* pObjectContext = NULL;
BSTR stRole = SysAllocString(L"Manager");
VARIANT_BOOL fIsInRole;
HRESULT hr;

hr = GetObjectContext(&pObjectContext);

// Find out if security is enabled.
if (pObjectContext->IsSecurityEnabled()) {
    //Then find out if the caller is in the right role.
    fIsInRole = pObjectContext->IsCallerInRole
        (stRole, &fIsInRole)
    SysFreeString(stRole);
    if (!fIsInRole) {
        // If not, do something appropriate here.
    }
}
else {
    // If security's not enabled, do something 
    // appropriate here.
}