A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

How to get exchange server address from C# Add-in?



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old February 7th 07, 10:57 PM posted to microsoft.public.outlook.program_addins
Piyush Gupta
external usenet poster
 
Posts: 9
Default How to get exchange server address from C# Add-in?

Hi All,

I am developing add-in for Outlook 2003 (for Exchange Server 2003)
using VSTO/C# 2005.

As I found during my research on Outlook object model, it doesn't
expose active directory security groups for the current user. To
determine whether current user belongs to a specific active directory
security group or not, I am executing LDAP query to get all security
groups belonging to the user.

Can you pls. point me the property/method to get exchange server
address where I can fire this LDAP query? It'll be great if you can
suggest another way to get security groups for the current user.

Thanks,
Piyush.

  #2  
Old February 8th 07, 03:38 AM posted to microsoft.public.outlook.program_addins
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default How to get exchange server address from C# Add-in?

Here is what I use to get the Exchange server name given a user name
(Delphi). Note that most likely than not the AD server name will be
different from that of the Exchange server.

function HrGetExchangeServerName(UserName : string):string;
var strCurrUserName, strCurrDomainName : string;
ADSIUser : IADsUser;
ADsNameTranslate : IADsNameTranslate;
DN : string;
Flags : integer;
res : HResult;
p : integer;
begin
p:=Pos('\', UserName);
if p 0 then begin
strCurrUserName:=Copy(UserName, p+1, MaxInt);
strCurrDomainName:=Copy(UserName, 1, p-1);
end
else begin
if not HrGetUserNameAndDomain(strCurrUserName, strCurrDomainName) then
raise EOleSysError.Create('Culd not retrieve current user''s network name
and domain', E_UNEXPECTED, 0);
end;
ADsNameTranslate:=CreateOleObject('NameTranslate') as IADsNameTranslate;
//DNL
ADsNameTranslate.Init(ADS_NAME_INITTYPE_DOMAIN, strCurrDomainName);
if Pos('\', UserName) 0 then Flags:=ADS_NAME_TYPE_NT4
else if Pos('@', UserName) 0 then Flags:=ADS_NAME_TYPE_DOMAIN_SIMPLE
else Flags:=ADS_NAME_TYPE_UNKNOWN;
ADsNameTranslate.Set_(Flags, UserName);
DN:=ADsNameTranslate.Get(ADS_NAME_TYPE_1779);
//find the LDAP object from the AD
res:=ADsGetObject(PWideChar(WideString('LDAP://' + strCurrDomainName + '/'
+ DN)), IID_IADsUser, pointer(ADSIUser));
CheckRaiseMAPIError(res, 'ADsGetObject');
ADSIUser.GetInfoEx(VarArrayOf(['msExchHomeServerName']), 0);
Result:=ADSIUser.Get('msExchHomeServerName');
p:=PosFromEnd('=', Result);
if p 0 then Result:=Copy(Result, p+1, MaxInt);
end;

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

"Piyush Gupta" wrote in message
oups.com...
Hi All,

I am developing add-in for Outlook 2003 (for Exchange Server 2003)
using VSTO/C# 2005.

As I found during my research on Outlook object model, it doesn't
expose active directory security groups for the current user. To
determine whether current user belongs to a specific active directory
security group or not, I am executing LDAP query to get all security
groups belonging to the user.

Can you pls. point me the property/method to get exchange server
address where I can fire this LDAP query? It'll be great if you can
suggest another way to get security groups for the current user.

Thanks,
Piyush.



 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Recipient.Address in Exchange Server Joel Outlook and VBA 3 December 8th 06 04:52 AM
Update address book automatically FROM EXCHANGE SERVER gchandrujs via OfficeKB.com Outlook - Using Contacts 2 November 10th 06 02:50 AM
Importing External Email Address To Exchange Server Lisa AGA Outlook - Using Contacts 1 October 23rd 06 11:00 PM
Cannot connect to Exchange server from Outlook client on Windows 2003 Server AllenM Outlook - General Queries 0 May 16th 06 06:44 PM
!!HELP!!! Cannot connect to Exchange Server from a RDP, ICA session or server local machine AllenM Outlook - General Queries 0 May 11th 06 10:14 PM


All times are GMT +1. The time now is 11:24 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.