Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Obtain the Exchange Directory Hierarchy Programmatically


View products that this article applies to.

This article was previously published under Q186334

↑ Back to the top


Summary

When writing backup software it is sometimes useful to get the hierarchy of the Exchange directory. This article describes how to programmatically get the Exchange hierarchy of the Exchange Directory.

↑ Back to the top


More information

The sample below uses a BackupListNode structure to hold the hierarchy.

This is what that structure looks like:

   typedef struct _BackupListNode
   {
            struct _BackupListNode __RPC_FAR *pnodeNext;
            struct _BackupListNode __RPC_FAR *pnodeChildren;
            RPC_SZ szName;
   } BackupListNode;


   //Program Start

   /*******************************************************************
   // This code returns a BackupListNode structure that
   // represents the Organizational Hierarchy of Exchange.
   //******************************************************************

   #define UNICODE
   #define _UNICODE
   #include <SADAPI.H> //this header is included in the Platform SDK
   #include <TCHAR.h>

   void main(void)
   {
      BackupListNode*      pNode           =    NULL;
      RPC_SC               sc;
      PRPCBINDINFO         pBindInfo       =    new RPCBINDINFO;
      TCHAR                wszServer[256];

      ZeroMemory(pBindInfo, sizeof(RPCBINDINFO));

      // Replace "ExchangeServer" with the server name you
      // want to get the hierarchy from
      _tcscpy(wszServer, L"ExchangeServer");

      sc = SAD_ScBind(pBindInfo, wszServer);

      if (sc != ERROR_SUCCESS)   return;

      sc = SAD_ScGetBackupListNodeW(pBindInfo->wszServer, &pNode);

      // pNode will contain your entire hierarchy as seen by
      // the Server (wszServer)

      SAD_FreeBackupListNode(pNode);

      SAD_Unbind(pBindInfo);

      delete pBindInfo;
   }
				
To build use the following Libraries:
Kernel32.lib
User32.lib
Advapi32.lib
Edkevent.lib
Gdi32.lib
Winspool.lib
Comdlg32.lib
Advapi32.lib
Shell32.lib
Ole32.lib
Oleaut32.lib
Uuid.lib
Edkmapi.lib
Edkdebug.lib
Msgemit.lib
Mapi32.lib
Edkguid.lib
Edkutils.lib
Gwmain.lib
Rtflib32.lib
Addrlkup.lib
Version.lib
Msvcrt.lib
Mblogon.lib
Exchinst.lib
Newpst.lib
Sadapi.lib
Rpcrt4.lib
Rpcndr.lib
Rpcns4.lib
Exclude the following Libraries:
Libc.lib
Libcd.lib

↑ Back to the top


Keywords: KB186334, kbhowto

↑ Back to the top

Article Info
Article ID : 186334
Revision : 4
Created on : 7/1/2004
Published on : 7/1/2004
Exists online : False
Views : 341