Group:  Microsoft Outlook ยป microsoft.public.outlook.program_addins
Thread: How to get exchange server address from C# Add-in?

Geek News

How to get exchange server address from C# Add-in?
"Piyush Gupta" <indorewale[ at ]gmail.com> 2/7/2007 10:57:19 PM
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.

Re: How to get exchange server address from C# Add-in?
"Dmitry Streblechenko" <dmitry[ at ]dimastr.com> 2/8/2007 3:38:01 AM
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('[ at ]', 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" <indorewale[ at ]gmail.com> wrote in message
news:1170889039.843238.297210[ at ]m58g2000cwm.googlegroups.com...
[Quoted Text]
> 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.
>


Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net