<p>There is a <a href="http://support.microsoft.com/?scid=194627" rel="nofollow noreferrer">Microsoft knowledge base article</a> with sample code to open all mailboxes in a given information store. It works so far (requires a bit of <a href="http://blogs.msdn.com/jasonjoh/archive/2004/08/01/204585.aspx" rel="nofollow noreferrer">copy &amp; pasting</a> on compilers newer than VC++ 6.0).</p>

<p>At one point it calls IExchangeManageStore::GetMailboxTable with the distinguished name of the information store. For the Exchange 2007 Trial Virtual Server image it has to look like this: </p>

<pre><code>"/o=Litware Inc/ou=Exchange Administrative Group (FYDIBOHF23SPDLT)/cn=Configuration/cn=servers/cn=DC1".
</code></pre>

<p>Using <a href="http://www.dimastr.com/outspy/" rel="nofollow noreferrer">OutlookSpy</a> and clicking on IMsgStore and IExchangeManageStore reveals the desired string next to "Server DN:".</p>

<p>I want to avoid forcing the user to put this into a config file. So if OutlookSpy can do it, how can my application find out the distinguished name of the information store where the currently open mailbox is on?</p>

[{'answer_id': 82342, 'author': 'Duncan Smart', 'author_id': 1278, 'author_profile': 'https://Stackoverflow.com/users/1278', 'pm_score': 0, 'selected': False, 'text': "<p>It'll be in Active Directory, so you'd use ADSI/LDAP to look at CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=<em>example</em>,DC=<em>com</em>. Use Sysinternals' ADExplorer to have a dig around in there to find the value you're looking for.</p>\n"}, {'answer_id': 90972, 'author': 'Sebastian Kirsche', 'author_id': 4097, 'author_profile': 'https://Stackoverflow.com/users/4097', 'pm_score': 3, 'selected': True, 'text': '<p>Thinking there must be a pure MAPI solution, I believe I\'ve figured out how OutlookSpy does it.\n<br><br><br>\nThe following code snippet, inserted after </p>\n\n<pre><code>printf("Created MAPI session\\n");\n</code></pre>\n\n<p>in the example from <a href="http://support.microsoft.com/kb/194627" rel="nofollow noreferrer">KB194627</a>, will show the <em>Server DN</em>.</p>\n\n<pre><code>LPPROFSECT lpProfSect;\nhr = lpSess-&gt;OpenProfileSection((LPMAPIUID)pbGlobalProfileSectionGuid, NULL, 0, &amp;lpProfSect);\nif(SUCCEEDED(hr))\n{\n    LPSPropValue lpPropValue;\n    hr = HrGetOneProp(lpProfSect, PR_PROFILE_HOME_SERVER_DN, &amp;lpPropValue);\n    if(SUCCEEDED(hr))\n    {\n        printf("Server DN: %s\\n", lpPropValue-&gt;Value.lpszA);\n        MAPIFreeBuffer(lpPropValue);\n    }\n    lpProfSect-&gt;Release();\n}\n</code></pre>\n\n<p><br><br>\n<strong>Update:</strong><br>\nThere is the function <em>HrGetServerDN</em> in the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=36a309c3-8c55-4476-8785-cafc59a2d075&amp;DisplayLang=en" rel="nofollow noreferrer">EDK 5.5 source code</a>, it extracts the <em>Server DN</em> from a given session\'s <em>PR_EMS_AB_HOME_MTA</em>. I\'ll try it if the other way turns out to be unreliable.</p>\n'}, {'answer_id': 400448, 'author': 'Cain T. S. Random', 'author_id': 45341, 'author_profile': 'https://Stackoverflow.com/users/45341', 'pm_score': 0, 'selected': False, 'text': "<p>I'd download the source for MFCMapi and see how they do this.</p>\n"}]
['https://Stackoverflow.com/questions/80831', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4097/']