I wrote this MAPI application for a customer the other day. The application uses the Outlook 2010 MAPI headers and some of the header files shipped with MFCMAPI. They are all included in the attached archive.

You can run the application to enable or disable cached mode by using the –E, respectively the –D switches. If you don’t specify a profile name, the application will process the default Outlook profile.

The command line switches are:

  • -E – enable cached mode
  • -D – disable cached mode
  • -P – allows specifying a profile name

For example: MAPISetCachedMode -E will enable cached mode on the default profile.  MAPISetCachedMode -E -P Outlook will enable cached mode on the profile named Outlook. Same applies for the -D switch. Please make sure you type the -E or -D before the -P switch. If you use the -P switch, please make sure you specify a profile name.

Below, the source code of the app:

 

// MAPISetCachedMode.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <stdio.h>
#include <InitGuid.h>
#include <iostream>
#define USES_IID_IMAPIProp
#include <MAPIGuid.h>
#include <mapix.h>
#include <MAPITags.h>
#include <MAPIUtil.h>
#include <MAPIDefS.h>
#include <MAPIUtil.h>
#include <cstring>
#include <wchar.h>
#include <mbstring.h>
#include <EdkMdb.h>


/*******************************************************************************
DisableCachedMode

This function will configure the PR_PROFILE_CONFIG_FLAGS property on existing MAPI profiles. It assumes that you have already initialized MAPI.

Parameters:
lpszProfile The name of the profile you are going to modify.

Output:
HRESULT hRes Returns S_OK if completed successfully, otherwise returns a MAPI error.
*******************************************************************************/

HRESULT DisableCachedMode(LPWSTR lpszProfile)
{
HRESULT hRes = S_OK; // Result code returned from MAPI calls.
LPPROFADMIN lpProfAdmin = NULL; // Profile Admin pointer.
LPSERVICEADMIN lpSvcAdmin = NULL; // Message Service Admin pointer.
LPPROVIDERADMIN lpProvAdmin = NULL; // Provider Admin pointer.
LPMAPITABLE lpMsgSvcTable = NULL; // MAPI table pointer.
LPPROFSECT lpProfileSection = NULL; // Profile Section Pointer.
LPSRowSet lpSvcRows = NULL; // Row set pointer.
SRestriction sres; // Restriction structure (used in HrQueryAllRows).
SPropValue SvcProps; // Property value structure used in restriction.
ULONG ulProps = 0; // Count of props.
ULONG cbNewBuffer = 0; // Count of bytes for new buffer.

// Enumeration for convenience.
enum {iDispName, iSvcName, iSvcUID, cptaSvc};

// This structure tells HrQueryAllRows what columns we want returned.
SizedSPropTagArray(cptaSvc,sptCols) = { cptaSvc, PR_DISPLAY_NAME, PR_SERVICE_NAME, PR_SERVICE_UID };

// This structure tells our GetProps call what properties to get from the global profile section.
SizedSPropTagArray(1, sptGlobal) = { 1, PR_STORE_PROVIDERS };

// Get an IProfAdmin interface.
hRes = MAPIAdminProfiles(0, // Flags
&lpProfAdmin); // Pointer to new IProfAdmin

if (FAILED(hRes)) goto error_handler;
printf("Retrieved IProfAdmin interface.\n");

// Get an IMsgServiceAdmin interface off of the IProfAdmin interface.
hRes = lpProfAdmin->AdminServices( lpszProfile,// Profile that we want to modify.
LPWSTR(""), // Password for that profile.
NULL, // Handle to parent window.
0, // Flags.
&lpSvcAdmin); // Pointer to new IMsgServiceAdmin.

if (FAILED(hRes)) goto error_handler;
printf("Retrieved IMsgServiceAdmin interface.\n");

// We now need to get the entry id for the Exchange service.
// First, we get the Message service table.
hRes = lpSvcAdmin->GetMsgServiceTable( 0, // Flags
&lpMsgSvcTable); // Pointer to table

if (FAILED(hRes)) goto error_handler;
printf("Retrieved message service table from profile.\n");

// Set up restriction to query table.
sres.rt = RES_CONTENT;
sres.res.resContent.ulFuzzyLevel = FL_FULLSTRING;
sres.res.resContent.ulPropTag = PR_SERVICE_NAME_A;
sres.res.resContent.lpProp = &SvcProps;
SvcProps.ulPropTag = PR_SERVICE_NAME_A;
SvcProps.Value.lpszA = "MSEMS";

// Query the table to get the entry for the Exchange message service.
hRes = HrQueryAllRows( lpMsgSvcTable,
(LPSPropTagArray)&sptCols,
&sres,
NULL,
0,
&lpSvcRows);

if (FAILED(hRes)) goto error_handler;
printf("Queried table for Exchange message service.\n");

if (lpSvcRows->cRows>0)
{
// Get a provider to the ProviderAdmin interface
hRes = lpSvcAdmin->AdminProviders( (LPMAPIUID)lpSvcRows->aRow->lpProps[iSvcUID].Value.bin.lpb,
0,
&lpProvAdmin);

if (FAILED(hRes)) goto error_handler;
printf("Retrieved IProviderAdmin interface\n");

LPMAPIPROP pMAPIProp=NULL;

// Open the Global Profile Section
hRes = lpProvAdmin->OpenProfileSection( (LPMAPIUID)pbGlobalProfileSectionGuid,
NULL,
MAPI_MODIFY,
&lpProfileSection);

if (hRes==S_OK)
{
hRes=lpProfileSection->QueryInterface(IID_IMAPIProp, (void**)&pMAPIProp);

// bind to the PR_PROFILE_CONFIG_FLAGS property
LPSPropValue profileConfigFlags = NULL;
hRes=HrGetOneProp(pMAPIProp,PR_PROFILE_CONFIG_FLAGS, &profileConfigFlags);

if (hRes==S_OK)
{
// Set the updated value for disabling cached mode
if (profileConfigFlags[0].Value.l & 0x980)
{
profileConfigFlags[0].Value.l = profileConfigFlags[0].Value.l ^ 0x980;
hRes=lpProfileSection->SetProps(1,profileConfigFlags,NULL);
hRes = lpProfileSection->SaveChanges(0);
}


}
if (profileConfigFlags) MAPIFreeBuffer(profileConfigFlags);
}

if (pMAPIProp) MAPIFreeBuffer(pMAPIProp);

if (FAILED(hRes)) goto error_handler;
printf("Finished processing changes\n");
}
goto cleanup;

error_handler:
printf("ERROR: hRes = %0x\n", hRes);

cleanup:
// Clean up.

if (lpSvcRows) FreeProws(lpSvcRows);
if (lpMsgSvcTable) lpMsgSvcTable->Release();
if (lpSvcAdmin) lpSvcAdmin->Release();
if (lpProfAdmin) lpProfAdmin->Release();
if (lpProvAdmin) lpProvAdmin->Release();
if (lpProfileSection) lpProfileSection->Release();

printf("Done cleaning up.\n");
printf("=============================================\n");
return hRes;
}


/*******************************************************************************
EnableCachedMode

This function will configure the PR_PROFILE_CONFIG_FLAGS property on existing MAPI profiles. It assumes that you have already initialized MAPI.

Parameters:
lpszProfile The name of the profile you are going to modify.

Output:
HRESULT hRes Returns S_OK if completed successfully, otherwise returns a MAPI error.
*******************************************************************************/

HRESULT EnableCachedMode(LPWSTR lpszProfile)
{
HRESULT hRes = S_OK; // Result code returned from MAPI calls.
LPPROFADMIN lpProfAdmin = NULL; // Profile Admin pointer.
LPSERVICEADMIN lpSvcAdmin = NULL; // Message Service Admin pointer.
LPPROVIDERADMIN lpProvAdmin = NULL; // Provider Admin pointer.
LPMAPITABLE lpMsgSvcTable = NULL; // MAPI table pointer.
LPPROFSECT lpProfileSection = NULL; // Profile Section Pointer.
LPSRowSet lpSvcRows = NULL; // Row set pointer.
SRestriction sres; // Restriction structure (used in HrQueryAllRows).
SPropValue SvcProps; // Property value structure used in restriction.
ULONG ulProps = 0; // Count of props.
ULONG cbNewBuffer = 0; // Count of bytes for new buffer.

// Enumeration for convenience.
enum {iDispName, iSvcName, iSvcUID, cptaSvc};

// This structure tells HrQueryAllRows what columns we want returned.
SizedSPropTagArray(cptaSvc,sptCols) = { cptaSvc, PR_DISPLAY_NAME, PR_SERVICE_NAME, PR_SERVICE_UID };

// This structure tells our GetProps call what properties to get from the global profile section.
SizedSPropTagArray(1, sptGlobal) = { 1, PR_STORE_PROVIDERS };

// Get an IProfAdmin interface.
hRes = MAPIAdminProfiles(0, // Flags
&lpProfAdmin); // Pointer to new IProfAdmin

if (FAILED(hRes)) goto error_handler;
printf("Retrieved IProfAdmin interface.\n");

// Get an IMsgServiceAdmin interface off of the IProfAdmin interface.
hRes = lpProfAdmin->AdminServices( lpszProfile,// Profile that we want to modify.
LPWSTR(""), // Password for that profile.
NULL, // Handle to parent window.
0, // Flags.
&lpSvcAdmin); // Pointer to new IMsgServiceAdmin.

if (FAILED(hRes)) goto error_handler;
printf("Retrieved IMsgServiceAdmin interface.\n");

// We now need to get the entry id for the Exchange service.
// First, we get the Message service table.
hRes = lpSvcAdmin->GetMsgServiceTable( 0, // Flags
&lpMsgSvcTable); // Pointer to table

if (FAILED(hRes)) goto error_handler;
printf("Retrieved message service table from profile.\n");

// Set up restriction to query table.
sres.rt = RES_CONTENT;
sres.res.resContent.ulFuzzyLevel = FL_FULLSTRING;
sres.res.resContent.ulPropTag = PR_SERVICE_NAME_A;
sres.res.resContent.lpProp = &SvcProps;
SvcProps.ulPropTag = PR_SERVICE_NAME_A;
SvcProps.Value.lpszA = "MSEMS";

// Query the table to get the entry for the Exchange message service.
hRes = HrQueryAllRows( lpMsgSvcTable,
(LPSPropTagArray)&sptCols,
&sres,
NULL,
0,
&lpSvcRows);

if (FAILED(hRes)) goto error_handler;
printf("Queried table for Exchange message service.\n");

if (lpSvcRows->cRows>0)
{
// Get a provider to the ProviderAdmin interface
hRes = lpSvcAdmin->AdminProviders( (LPMAPIUID)lpSvcRows->aRow->lpProps[iSvcUID].Value.bin.lpb,
0,
&lpProvAdmin);

if (FAILED(hRes)) goto error_handler;
printf("Retrieved IProviderAdmin interface\n");

LPMAPIPROP pMAPIProp=NULL;

// Open the Global Profile Section
hRes = lpProvAdmin->OpenProfileSection( (LPMAPIUID)pbGlobalProfileSectionGuid,
NULL,
MAPI_MODIFY,
&lpProfileSection);

if (hRes==S_OK)
{
hRes=lpProfileSection->QueryInterface(IID_IMAPIProp, (void**)&pMAPIProp);

// bind to the PR_PROFILE_CONFIG_FLAGS property
LPSPropValue profileConfigFlags = NULL;
hRes=HrGetOneProp(pMAPIProp,PR_PROFILE_CONFIG_FLAGS, &profileConfigFlags);

if (hRes==S_OK)
{
if (!(profileConfigFlags[0].Value.l & 0x980))
{
profileConfigFlags[0].Value.l = profileConfigFlags[0].Value.l ^ 0x980;
hRes=lpProfileSection->SetProps(1,profileConfigFlags,NULL);
hRes = lpProfileSection->SaveChanges(0);
}
}
if (profileConfigFlags) MAPIFreeBuffer(profileConfigFlags);
}

if (pMAPIProp) MAPIFreeBuffer(pMAPIProp);

if (FAILED(hRes)) goto error_handler;
printf("Finished processing changes\n");
}
goto cleanup;

error_handler:
printf("ERROR: hRes = %0x\n", hRes);

cleanup:
// Clean up.

if (lpSvcRows) FreeProws(lpSvcRows);
if (lpMsgSvcTable) lpMsgSvcTable->Release();
if (lpSvcAdmin) lpSvcAdmin->Release();
if (lpProfAdmin) lpProfAdmin->Release();
if (lpProvAdmin) lpProvAdmin->Release();
if (lpProfileSection) lpProfileSection->Release();

printf("Done cleaning up.\n");
printf("=============================================\n");
return hRes;
}

/*******************************************************************************
EnableOnSpecificProfile

This function will retrieve the specified profile from the profiles table and call UpdateProfile. It assumes that you have already initialized MAPI.

Parameters:
lpszProfile The name of the profile you are going lookup.

Output:
HRESULT hRes Returns S_OK if completed successfully, otherwise returns a MAPI error.
*******************************************************************************/

HRESULT EnableOnSpecificProfile(LPSTR lpszProfile)
{
HRESULT hRes = S_OK;
LPPROFADMIN lpProfAdmin = NULL; // Profile Admin pointer
LPSERVICEADMIN lpSvcAdmin = NULL; // Message Service Admin pointer
LPMAPITABLE lpProfileTable = NULL; // Profiles Table pointer
SRestriction sres; // Search restriction
SPropValue spvProperty;
LPSRowSet pRow = NULL;

LPSTR lpDisplayName = NULL;

// Retrieve profile table
hRes = MAPIAdminProfiles(0, &lpProfAdmin);
if (!lpProfAdmin)
{
printf("Failed to retrieve profile interface.\n");
return hRes;
}
// Get profile table
hRes=lpProfAdmin->GetProfileTable(0, &lpProfileTable);
if (!lpProfileTable)
{
printf("Failed to read profiles.\n");
return hRes;
}
// Now go through the profile table and process each one

// build a restriction where PR_DISPLAY_NAME_A is the specified profile name
spvProperty.ulPropTag = PR_DISPLAY_NAME_A;
spvProperty.Value.lpszA = lpszProfile;

sres.rt = RES_CONTENT;
sres.res.resContent.ulFuzzyLevel = FL_FULLSTRING;
sres.res.resContent.ulPropTag = PR_DISPLAY_NAME_A;
sres.res.resContent.lpProp = &spvProperty;

hRes = lpProfileTable->Restrict(&sres, TBL_BATCH);

hRes = lpProfileTable->FindRow(&sres, BOOKMARK_BEGINNING, 0);

// we have a match
hRes = lpProfileTable->QueryRows(1,0,&pRow);
if (SUCCEEDED(hRes))
{
if (pRow->cRows > 0)
{
EnableCachedMode(pRow->aRow[0].lpProps[0].Value.lpszW);
}
else
printf("Profile not found!.\n");
}

lpProfileTable->Release();
lpProfAdmin->Release();
return hRes;
}


/*******************************************************************************
DisableOnSpecificProfile

This function will retrieve the specified profile from the profiles table and call UpdateProfile. It assumes that you have already initialized MAPI.

Parameters:
lpszProfile The name of the profile you are going lookup.

Output:
HRESULT hRes Returns S_OK if completed successfully, otherwise returns a MAPI error.
*******************************************************************************/

HRESULT DisableOnSpecificProfile(LPSTR lpszProfile)
{
HRESULT hRes = S_OK;
LPPROFADMIN lpProfAdmin = NULL; // Profile Admin pointer
LPSERVICEADMIN lpSvcAdmin = NULL; // Message Service Admin pointer
LPMAPITABLE lpProfileTable = NULL; // Profiles Table pointer
SRestriction sres; // Search restriction
SPropValue spvProperty;
LPSRowSet pRow = NULL;

LPSTR lpDisplayName = NULL;

// Retrieve profile table
hRes = MAPIAdminProfiles(0, &lpProfAdmin);
if (!lpProfAdmin)
{
printf("Failed to retrieve profile interface.\n");
return hRes;
}
// Get profile table
hRes=lpProfAdmin->GetProfileTable(0, &lpProfileTable);
if (!lpProfileTable)
{
printf("Failed to read profiles.\n");
return hRes;
}
// Now go through the profile table and process each one

// build a restriction where PR_DISPLAY_NAME_A is the specified profile name
spvProperty.ulPropTag = PR_DISPLAY_NAME_A;
spvProperty.Value.lpszA = lpszProfile;

sres.rt = RES_CONTENT;
sres.res.resContent.ulFuzzyLevel = FL_FULLSTRING;
sres.res.resContent.ulPropTag = PR_DISPLAY_NAME_A;
sres.res.resContent.lpProp = &spvProperty;

hRes = lpProfileTable->Restrict(&sres, TBL_BATCH);

hRes = lpProfileTable->FindRow(&sres, BOOKMARK_BEGINNING, 0);

// we have a match
hRes = lpProfileTable->QueryRows(1,0,&pRow);
if (SUCCEEDED(hRes))
{
if (pRow->cRows > 0)
{
DisableCachedMode(pRow->aRow[0].lpProps[0].Value.lpszW);
}
else
printf("Profile not found!.\n");
}

lpProfileTable->Release();
lpProfAdmin->Release();
return hRes;
}

/*******************************************************************************
EnableOnDefaultProfile

This function will retrieve the default profile profile from the profiles table and call UpdateProfile. It assumes that you have already initialized MAPI.

Parameters:
lpszProfile The name of the profile you are going lookup.

Output:
HRESULT hRes Returns S_OK if completed successfully, otherwise returns a MAPI error.
*******************************************************************************/

HRESULT EnableOnDefaultProfile()
{
HRESULT hRes = S_OK;
LPPROFADMIN lpProfAdmin = NULL; // Profile Admin pointer
LPSERVICEADMIN lpSvcAdmin = NULL; // Message Service Admin pointer
LPMAPITABLE lpProfileTable = NULL; // Profiles Table pointer
SRestriction sres; // Search restriction
SPropValue spvProperty;
LPSRowSet pRow = NULL;

LPSTR lpDisplayName = NULL;

// Retrieve profile table
hRes = MAPIAdminProfiles(0, &lpProfAdmin);
if (!lpProfAdmin)
{
printf("Failed to retrieve profile interface.\n");
return hRes;
}
// Get profile table
hRes=lpProfAdmin->GetProfileTable(0, &lpProfileTable);
if (!lpProfileTable)
{
printf("Failed to read profiles.\n");
return hRes;
}
// Now go through the profile table and process each one

// build a restriction where PR_DEFAULT_PROFILE = TRUE
spvProperty.ulPropTag = PR_DEFAULT_PROFILE;
spvProperty.Value.b = TRUE;

sres.rt = RES_PROPERTY;
sres.res.resProperty.relop = RELOP_EQ;
sres.res.resProperty.ulPropTag = PR_DEFAULT_PROFILE;
sres.res.resProperty.lpProp = &spvProperty;

hRes = lpProfileTable->Restrict(&sres, TBL_BATCH);

hRes = lpProfileTable->FindRow(&sres, BOOKMARK_BEGINNING, 0);

// we have a match
hRes = lpProfileTable->QueryRows(1,0,&pRow);
if (SUCCEEDED(hRes))
{
if (pRow->cRows > 0)
{
EnableCachedMode(pRow->aRow[0].lpProps[0].Value.lpszW);
}
else
printf("Profile not found!.\n");
}

lpProfileTable->Release();
lpProfAdmin->Release();
return hRes;
}

/*******************************************************************************
DisableOnDefaultProfile

This function will retrieve the default profile profile from the profiles table and call UpdateProfile. It assumes that you have already initialized MAPI.

Parameters:
lpszProfile The name of the profile you are going lookup.

Output:
HRESULT hRes Returns S_OK if completed successfully, otherwise returns a MAPI error.
*******************************************************************************/

HRESULT DisableOnDefaultProfile()
{
HRESULT hRes = S_OK;
LPPROFADMIN lpProfAdmin = NULL; // Profile Admin pointer
LPSERVICEADMIN lpSvcAdmin = NULL; // Message Service Admin pointer
LPMAPITABLE lpProfileTable = NULL; // Profiles Table pointer
SRestriction sres; // Search restriction
SPropValue spvProperty;
LPSRowSet pRow = NULL;

LPSTR lpDisplayName = NULL;

// Retrieve profile table
hRes = MAPIAdminProfiles(0, &lpProfAdmin);
if (!lpProfAdmin)
{
printf("Failed to retrieve profile interface.\n");
return hRes;
}
// Get profile table
hRes=lpProfAdmin->GetProfileTable(0, &lpProfileTable);
if (!lpProfileTable)
{
printf("Failed to read profiles.\n");
return hRes;
}
// Now go through the profile table and process each one

// build a restriction where PR_DEFAULT_PROFILE = TRUE
spvProperty.ulPropTag = PR_DEFAULT_PROFILE;
spvProperty.Value.b = TRUE;

sres.rt = RES_PROPERTY;
sres.res.resProperty.relop = RELOP_EQ;
sres.res.resProperty.ulPropTag = PR_DEFAULT_PROFILE;
sres.res.resProperty.lpProp = &spvProperty;

hRes = lpProfileTable->Restrict(&sres, TBL_BATCH);

hRes = lpProfileTable->FindRow(&sres, BOOKMARK_BEGINNING, 0);

// we have a match
hRes = lpProfileTable->QueryRows(1,0,&pRow);
if (SUCCEEDED(hRes))
{
if (pRow->cRows > 0)
{
DisableCachedMode(pRow->aRow[0].lpProps[0].Value.lpszW);
}
else
printf("Profile not found!.\n");
}

lpProfileTable->Release();
lpProfAdmin->Release();
return hRes;
}

int _tmain(int argc, _TCHAR* argv[])
{
if (3 <= argc)
{
LPSTR arg1 = new CHAR[lstrlenW(argv[1])+1];
WideCharToMultiByte(CP_ACP, 0, argv[1], -1, arg1, lstrlenW(argv[1])+1, 0, 0);

LPSTR arg2 = new CHAR[lstrlenW(argv[2])+1];
WideCharToMultiByte(CP_ACP, 0, argv[2], -1, arg2, lstrlenW(argv[2])+1, 0, 0);

HRESULT hRes = S_OK;

if ((strncmp(arg1,"-D", strlen("-D")) == 0) || (strncmp(arg1,"-d", strlen("-d")) == 0) )
{
if ((strncmp(arg2,"-P", strlen("-P")) == 0) || (strncmp(arg2,"-p", strlen("-p")) == 0) )
{
printf("Processing one profile.\n");
MAPIInitialize(NULL);
LPSTR arg3 = new CHAR[lstrlenW(argv[3])+1];
WideCharToMultiByte(CP_ACP, 0, argv[3], -1, arg3, lstrlenW(argv[3])+1, 0, 0);
DisableOnSpecificProfile(arg3);
MAPIUninitialize();
}
else
{
printf("Invalid option. Please use \"-E\" to enable cached mode or \"-D\" to disable cached mode in the default profile.\n");
printf("Additionally you can use \"-P\" followed by the profile name to process a specific profile.");
printf("For example MAPISetCachedMode.exe -E or MAPISetCachedMode.exe -E -P \"Outlook\" or MAPISetCachedMode.exe -D or MAPISetCachedMode.exe -D -P \"Outlook\"");
}
}
else
{
if ((strncmp(arg1,"-E", strlen("-E")) == 0) || (strncmp(arg1,"-e", strlen("-e")) == 0) )
{
if ((strncmp(arg2,"-P", strlen("-P")) == 0) || (strncmp(arg2,"-p", strlen("-p")) == 0) )
{
printf("Processing one profile.\n");
MAPIInitialize(NULL);
LPSTR arg3 = new CHAR[lstrlenW(argv[3])+1];
WideCharToMultiByte(CP_ACP, 0, argv[3], -1, arg3, lstrlenW(argv[3])+1, 0, 0);
EnableOnSpecificProfile(arg3);
MAPIUninitialize();
}
else
{
printf("Invalid option. Please use \"-E\" to enable cached mode or \"-D\" to disable cached mode in the default profile.\n");
printf("Additionally you can use \"-P\" followed by the profile name to process a specific profile.");
printf("For example MAPISetCachedMode.exe -E or MAPISetCachedMode.exe -E -P \"Outlook\" or MAPISetCachedMode.exe -D or MAPISetCachedMode.exe -D -P \"Outlook\"");
}
}
else
{
printf("Invalid option. Please use \"-E\" to enable cached mode or \"-D\" to disable cached mode in the default profile.\n");
printf("Additionally you can use \"-P\" followed by the profile name to process a specific profile.");
printf("For example MAPISetCachedMode.exe -E or MAPISetCachedMode.exe -E -P \"Outlook\" or MAPISetCachedMode.exe -D or MAPISetCachedMode.exe -D -P \"Outlook\"");
}
}
}
else
{
if (2 <= argc)
{
LPSTR arg1 = new CHAR[lstrlenW(argv[1])+1];
WideCharToMultiByte(CP_ACP, 0, argv[1], -1, arg1, lstrlenW(argv[1])+1, 0, 0);
if ((strncmp(arg1,"-D", strlen("-D")) == 0) || (strncmp(arg1,"-d", strlen("-d")) == 0) )
{
printf("Disabling cached node on default profile.\n");
MAPIInitialize(NULL);
DisableOnDefaultProfile();
MAPIUninitialize();
}
else
{
if ((strncmp(arg1,"-E", strlen("-E")) == 0) || (strncmp(arg1,"-e", strlen("-e")) == 0) )
{
printf("Enabling cached mode on default profile.\n");
MAPIInitialize(NULL);
EnableOnDefaultProfile();
MAPIUninitialize();
}
else
{
printf("Invalid option. Please use \"-E\" to enable cached mode or \"-D\" to disable cached mode in the default profile.\n");
printf("Additionally you can use \"-P\" followed by the profile name to process a specific profile.");
printf("For example MAPISetCachedMode.exe -E or MAPISetCachedMode.exe -E -P \"Outlook\" or MAPISetCachedMode.exe -D or MAPISetCachedMode.exe -D -P \"Outlook\"");
}
}
}
else
{
printf("Invalid option. Please use \"-E\" to enable cached mode or \"-D\" to disable cached mode in the default profile.\n");
printf("Additionally you can use \"-P\" followed by the profile name to process a specific profile.");
printf("For example MAPISetCachedMode.exe -E or MAPISetCachedMode.exe -E -P \"Outlook\" or MAPISetCachedMode.exe -D or MAPISetCachedMode.exe -D -P \"Outlook\"");
}
}
return 0;
}