No way, customer requires this. Originally I wish to use the registration form to change it, and the results found that the registry is not read at all. It is difficult to find everything we need.
Then I want to be an OULOOK AddIN to judge, then directly setdefaultStore. The results found that setDefaultStore does not support VB.
Since you have to use VC , what addin is not expensive. Directly on Win32 Console App.
The method is simple,
Use Mapilogonex to log in to the current profile.
GetMsgStoStable reads all storage.
Decision PR_DEFAULT_STORE is on the server. If not, use getMsgStoreStable to find the server storage and use the setDefaultstore to run.
It's not easy to write, you wrote 3:30. This is sleeping.
Let Source Code is good first.
// setMydefaultStore.cpp // NEED MAPI32.LIB
#include "stdafx.h"
#include
#include
#include
#include
#define debug (status <0)
__INT8 Debug;
STDMETHODIMP SETDEFSTORE
LPMAPISESSION LPMAPISession;
STDMETHODIMP GETDEFSTORE
LPMAPISESSION LPMAPISession;
Void Displayusage ();
Int main (int Argc, char * argv [])
{
HRESULT HRES;
LPMAPISESSION LPMAPISESSION = NULL;
LPMDB LPMDB = NULL;
LPMapiFolder LPinBoxFolder = NULL;
LPSPROPVALUE TMP = NULL;
Flags flogon = MAPI_NO_MAIL | MAPI_USE_DEFAULT;
Debug = 0;
IF (Argc> 2)
{
DISPLAYUSAGE ();
Goto quit1;
}
IF (argc == 2)
{
IF (_Stricmp (Argv [1], "/ D") == 0) || (_strics (argv [1], "/ d") == 0))
Debug = -1;
Else
{
DISPLAYUSAGE ();
Goto quit1;
}
}
HRES = Mapiinitialize (NULL);
IF (Failed (HRES) Goto Quit;
IF debug (debug) FLLOGON = MAPI_LOGON_UI;
HRES = Mapilogonex (0,
Null, // Profile Name
Null, // Password - this Parameter Should Always Be Null
FLLOGON, / / MAPI_LOGON_UI, / / ALLOW A Profile Picker Box To Show if Not Logged in
& lpMapisession); // Handle of Session
IF (Failed (HRES) Goto Quit;
HRES = getDefstore (LPMAPISession);
IF (Failed (HRES) Goto Quit; Quit:
IF (TMP) MapifreeBuffer (TMP);
Ulrelease (lpinboxfolder);
Ulrelease (LPMDB);
Ulrelease (LPMAPISession);
MapiunInitialize ();
IF (Failed (HRES))
{
Printf ("Failed with HRES OF% X / N", HRES);
}
Quit1:
// Printf ("Hit Any Key To Continue / N);
// While (! _ kbhit ()) {Sleep (50);
Return 0;
}
STDMETHODIMP GETDEFSTORE
LPMAPISESSION LPMAPISession)
{
LPMapITable Pstorestbl = NULL;
LPSROWSET ProW = NULL;
Static Srestment Sres;
SpropValue SPV;
HRESULT HRES;
LPMDB LPTEMPMDB = NULL;
// Will Retrieve Provider Name Only
// Two Types of provider We will accept
// Microsoft Exchange Server
// Personal Folders
ENUM {provider, num_cols};
Static sizedsproptagarray (num_cols, sptcols) = {num_cols, pr_provider_display};
// Get The Table of All The Message Stores Available
HRES = LPMAPISESSION -> GETMSGSTORESTABLE (0, & PstoreStbl);
IF (Failed (HRES) Goto Quit;
// set up restriction for the default store
Sres.rt = res_property; // comparing a property
Sres.res.Resproperty.RELOP = RELOP_EQ; //
Test
ING Equality
Sres.res.Resproperty.ulproptag = pr_default_store; // tag to compare
Sres.res.resproperty.lpprop = & spv; //prop tag and value to compare against
Spv.ulproptag = pr_default_store; // Tag Type
SPV.Value.b = true; // tag value
// Convert the Table to an Array Which Can Be Stepped THROUGH
// Query All Rows WITHOUT ANY RESTRICTIONS. Thus all rows get returned.
HRES = HRQUERYALLROWS
Pstorestbl, // Table to Query
(LPSPropTagArray) & sptCols, // Which columns to get // If the ptaga parameter is NULL, HrQueryAllRows retrieves the entire column set of the current table view passed in the ptable parameter & sres, // If the pres parameter is NULL, HrQueryAllRows makes no restrictions .
Null, // no sort order
0, // Max Number of Rows (0 means no limit)
& prop); // array to return
IF (Failed (HRES) Goto Quit;
// There SHOULD BE Only One Row Which Is Default Message Store.
LPSTR STROVNAME = ProW-> Arow [0] .lpprops [provider] .value.lpsza;
// Default Store's Provider Can Be Only Microsoft Exchange Server and Personal Folders.
// if the store's provide starts with 'm', the user's server mailbox is buy. We then need to do not do nothing.
// if The Store's Provider Does Not Start with 'M', a Personal Folder IS Used. We Then NEED TOET IT TO A Server Store.
IF ('m' == Strovname [0])
{
IF debug (debug) Printf ("The Current Store Is on The Exchange Server./N");
IF debug (debug) Printf ("We need to do not nothing and will qit the program);
Goto quit;
}
IF debug (debug) Printf ("The Current Store Is on A Personal Folder./N");
IF debug (debug) Printf ("We Need to Locate The Store of The Exchange Server and Change The Default Store In this profile! / n");
SetDefstore (LPMAPISession);
// ALWAYS CLEAN UP YOUR Memory Here!
Quit:
FreePROWS (ProW);
Ulrelease (PstoreStbl);
IF (Failed (HRES))
{
HRESULT HR;
LPMAPIERROR LPERROR;
HR = lpMapising-> getLastError (HRES, 0, & lPerror);
IF (! hr)
{
Printf ("% S / N% S / N", lPerror-> lpszerror, lPerror-> lpszcomponent;
MapifreeBuffer (LPERROR);
}
}
Return HRES;
}
STDMETHODIMP SETDEFSTORE (LPMAPISESSION LPMAPISession) {
LPMapITable Pstorestbl = NULL;
LPSROWSET ProW = NULL;
Static Srestment Sres;
HRESULT HRES;
LPMDB LPTEMPMDB = NULL;
Enum {EID, Name, Provider, num_cols};
Static sizedsproptagarray (num_cols, sptcols) = {num_cols, pr_entryid, pr_display_name, pr_provider_display};
// Get The Table of All The Message Stores Available
HRES = LPMAPISESSION -> GETMSGSTORESTABLE (0, & PstoreStbl);
IF (Failed (HRES) Goto Quit;
// Convert the Table to an Array Which Can Be Stepped THROUGH
// only one message store sales sales pra_default_store set to true, so Only one will be returned
HRES = HRQUERYALLROWS
Pstorestbl, // Table to Query
(LpsproptagArray) & SPTCOLS, // Which columns to get
Null, // no restriction
Null, // no sort order
0, // Max Number of Rows (0 means no limit)
& prop); // array to return
IF (Failed (HRES) Goto Quit;
// browse to all rows in the rowset.
// ulong i = 0;
// ulong loopcount = process = prow-> crows;
// DO
For (ulong i = 0; i
{
LPSTR STROVNAME = ProW-> AROW [i] .lpprops [provider] .value.lpsza;
LPSTR STRNAME = ProW-> AROW [i] .lpprops [name] .value.lpsza;
IF (('m' == strprovname [0]) && ('p'! = Strname [0]))))
{
IF debug (debug) Printf ("Change Default Store for ... / N);
IF debug (debug) Printf (Strovname);
IF debug (debug) Printf ("/ t");
IF debug (debug) Printf (STRNAME);
IF debug (debug) Printf ("/ n");
HRES = lpMapising-> setdefaultstore
MAPI_DEFAULT_STORE, // Establishes the message store as the session default. Updates the message store's status table row by setting the STATUS_DEFAULT_STORE flag in the PR_RESOURCE_FLAGS column.pRow-> aRow [i] .lpProps [EID] .Value.bin.cb, / .
(LpenTryid) ProW-> Arow [i] .lpprops [eid] .value.bin.lpb); // Pointer to the entry Identifier of the message store intended as the default.
IF (! failed (hres)) BREAK;
}
}
// ALWAYS CLEAN UP YOUR Memory Here!
Quit:
FreePROWS (ProW);
Ulrelease (PstoreStbl);
IF (Failed (HRES))
{
HRESULT HR;
LPMAPIERROR LPERROR;
HR = lpMapising-> getLastError (HRES, 0, & lPerror);
IF (! hr)
{
Printf ("% S / N% S / N", lPerror-> lpszerror, lPerror-> lpszcomponent;
MapifreeBuffer (LPERROR);
}
}
Return HRES;
}
Void DisplayUsage ()
{
Printf ("The Syntax of The Command Is IncorRect./N");
Printf ("USAGE: / N");
Printf ("SETMYDEFAULTSTORE [/ D] / N");
Printf ("[/ d] / t shows debug information./n");
}