PC Review


Reply
Thread Tools Rate Thread

Getting user's AD account

 
 
khai
Guest
Posts: n/a
 
      16th Jan 2009
How can I get the user's AD account (i.e. username) via my Outlook plug-in in
C#?
 
Reply With Quote
 
 
 
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      16th Jan 2009
NameSpace.CurrentUser.AddressEntry returns an AddressEntry object. Use
AddressEntry.Name or AddressEntry.Address to get whichever you want. Address
will be in EX form as an EX DN.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"khai" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> How can I get the user's AD account (i.e. username) via my Outlook plug-in
> in
> C#?


 
Reply With Quote
 
 
 
 
Dmitry Streblechenko
Guest
Posts: n/a
 
      16th Jan 2009
Outlook2007 only:
Application.Session.CurrentUser.AddressEntry.GetExchangeUser.
You can then use ExchangeUser.Alias property.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"khai" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> How can I get the user's AD account (i.e. username) via my Outlook plug-in
> in
> C#?



 
Reply With Quote
 
khai
Guest
Posts: n/a
 
      19th Jan 2009
This works for getting the sender's account. But how can I get the
recipient's AD account?

I have also noticed that in the Outlook address book, some of the user's
email address (i.e. ... /cn=...) is not the same as the alias field. I need
to get the user's AD account (i.e. login information) as I would like to
programmatically assign the ACL based on the recipients list.

"Ken Slovak - [MVP - Outlook]" wrote:

> NameSpace.CurrentUser.AddressEntry returns an AddressEntry object. Use
> AddressEntry.Name or AddressEntry.Address to get whichever you want. Address
> will be in EX form as an EX DN.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "khai" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > How can I get the user's AD account (i.e. username) via my Outlook plug-in
> > in
> > C#?

>
>

 
Reply With Quote
 
khai
Guest
Posts: n/a
 
      19th Jan 2009
Is there a workaround for Outlook 2003?

"Dmitry Streblechenko" wrote:

> Outlook2007 only:
> Application.Session.CurrentUser.AddressEntry.GetExchangeUser.
> You can then use ExchangeUser.Alias property.
>
> --
> Dmitry Streblechenko (MVP)
> http://www.dimastr.com/
> OutlookSpy - Outlook, CDO
> and MAPI Developer Tool
> -
> "khai" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > How can I get the user's AD account (i.e. username) via my Outlook plug-in
> > in
> > C#?

>
>
>

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      19th Jan 2009
To query the AD directly you would need to use an LDAP query, assuming you
have permissions to run that. Take a look at
http://www.outlookcode.com/threads.a...messageid=3870 and also
search on other links at www.outlookcode.com on "LDAP" for examples of how
to do that.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"khai" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> This works for getting the sender's account. But how can I get the
> recipient's AD account?
>
> I have also noticed that in the Outlook address book, some of the user's
> email address (i.e. ... /cn=...) is not the same as the alias field. I
> need
> to get the user's AD account (i.e. login information) as I would like to
> programmatically assign the ACL based on the recipients list.


 
Reply With Quote
 
Dmitry Streblechenko
Guest
Posts: n/a
 
      19th Jan 2009
As Ken mentioned, you can either
1. run an AD query,
2. use Extended MAPI (C++ or Delphi) to read the PR_ACCOUNT property from
the coresponding IMailUser object or
3. <plug> use Redemption - it exposes RDOAddressEntry.Alias property and
workds in all versions of Outlook </plug>.

--
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
-
"khai" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> Is there a workaround for Outlook 2003?
>
> "Dmitry Streblechenko" wrote:
>
>> Outlook2007 only:
>> Application.Session.CurrentUser.AddressEntry.GetExchangeUser.
>> You can then use ExchangeUser.Alias property.
>>
>> --
>> Dmitry Streblechenko (MVP)
>> http://www.dimastr.com/
>> OutlookSpy - Outlook, CDO
>> and MAPI Developer Tool
>> -
>> "khai" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > How can I get the user's AD account (i.e. username) via my Outlook
>> > plug-in
>> > in
>> > C#?

>>
>>
>>



 
Reply With Quote
 
khai
Guest
Posts: n/a
 
      20th Jan 2009
Are you referring to the following:
'*** Get the current User
Dim oWNetwork
Set oWNetwork = CreateObject("WScript.Network")
Set oRootDSE = GetObject("LDAP://RootDSE")
Set oMyDomain = GetObject("LDAP://" & _
oRootDSE.Get("defaultNamingContext"))
Set cnn = CreateObject("ADODB.Connection")
cnn.provider = "adsDSOObject"
cnn.Open oMyDomain.ADSPath
Set rst = CreateObject("ADODB.Recordset")

'*** UserPath in AD
StrSQL = "SELECT adspath " &_
"FROM '" & oMyDomain.ADSPath & "'" & _
"WHERE SAMAccountName ='" & oWNetwork.UserName & "'"
rst.Open StrSQL, cnn
ADUserPath = rst.Fields("adspath")
Set ADAccount = GetObject(ADUserPath)

'*** Users Data
Item.UserProperties.Find("UserName") = ADAccount.FullName
Item.UserProperties.Find("UserInitials") = ADAccount.initials
Item.UserProperties.Find("userPhone") = ADAccount.telephoneNumber

Is there a C# version?

"Ken Slovak - [MVP - Outlook]" wrote:

> To query the AD directly you would need to use an LDAP query, assuming you
> have permissions to run that. Take a look at
> http://www.outlookcode.com/threads.a...messageid=3870 and also
> search on other links at www.outlookcode.com on "LDAP" for examples of how
> to do that.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "khai" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > This works for getting the sender's account. But how can I get the
> > recipient's AD account?
> >
> > I have also noticed that in the Outlook address book, some of the user's
> > email address (i.e. ... /cn=...) is not the same as the alias field. I
> > need
> > to get the user's AD account (i.e. login information) as I would like to
> > programmatically assign the ACL based on the recipients list.

>
>

 
Reply With Quote
 
Ken Slovak - [MVP - Outlook]
Guest
Posts: n/a
 
      20th Jan 2009
Yes, that's the sort of LDAP query you'd need. Google is your friend for
trying to find a C# example of an LDAP query.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.
http://www.slovaktech.com/products.htm


"khai" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Are you referring to the following:
> '*** Get the current User
> Dim oWNetwork
> Set oWNetwork = CreateObject("WScript.Network")
> Set oRootDSE = GetObject("LDAP://RootDSE")
> Set oMyDomain = GetObject("LDAP://" & _
> oRootDSE.Get("defaultNamingContext"))
> Set cnn = CreateObject("ADODB.Connection")
> cnn.provider = "adsDSOObject"
> cnn.Open oMyDomain.ADSPath
> Set rst = CreateObject("ADODB.Recordset")
>
> '*** UserPath in AD
> StrSQL = "SELECT adspath " &_
> "FROM '" & oMyDomain.ADSPath & "'" & _
> "WHERE SAMAccountName ='" & oWNetwork.UserName & "'"
> rst.Open StrSQL, cnn
> ADUserPath = rst.Fields("adspath")
> Set ADAccount = GetObject(ADUserPath)
>
> '*** Users Data
> Item.UserProperties.Find("UserName") = ADAccount.FullName
> Item.UserProperties.Find("UserInitials") = ADAccount.initials
> Item.UserProperties.Find("userPhone") = ADAccount.telephoneNumber
>
> Is there a C# version?
>
> "Ken Slovak - [MVP - Outlook]" wrote:
>
>> To query the AD directly you would need to use an LDAP query, assuming
>> you
>> have permissions to run that. Take a look at
>> http://www.outlookcode.com/threads.a...messageid=3870 and also
>> search on other links at www.outlookcode.com on "LDAP" for examples of
>> how
>> to do that.
>>
>> --
>> Ken Slovak
>> [MVP - Outlook]
>> http://www.slovaktech.com
>> Author: Professional Programming Outlook 2007.
>> Reminder Manager, Extended Reminders, Attachment Options.
>> http://www.slovaktech.com/products.htm
>>
>>
>> "khai" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > This works for getting the sender's account. But how can I get the
>> > recipient's AD account?
>> >
>> > I have also noticed that in the Outlook address book, some of the
>> > user's
>> > email address (i.e. ... /cn=...) is not the same as the alias field. I
>> > need
>> > to get the user's AD account (i.e. login information) as I would like
>> > to
>> > programmatically assign the ACL based on the recipients list.

>>
>>


 
Reply With Quote
 
khai
Guest
Posts: n/a
 
      21st Jan 2009
I found a workaround:

##############################
Domain dmn = Domain.GetCurrentDomain();
DirectoryContext ctx = new DirectoryContext(DirectoryContextType.Domain,
dmn.Name);
DomainControllerCollection dcc = DomainController.FindAll(ctx);

foreach(DomainController dc in dcc)
{
DirectorySearcher ds;
using (ds = dc.GetDirectorySearcher())
{
ds.Filter = String.Format("(email=" + emailAcc + ")");
}
SearchResult sr = ds.FindOne();
ResultPropertyCollection rpc = sr.Properties;
foreach(string prop in rpc.PropertyNames)
{
foreach(Object obj in rpc[prop])
{
if (prop.ToLower() == "mailnickname")
{
userName = obj.ToString();
}
}
}
}
....
#################################

This works on my development environment. However when I port this over to
my production environment, I receive the following error:

"The server is not operational"

@ line 'SearchResult sr = ds.FindOne();'

I tried with FindAll(), but receive the same error.

Is there an explanation or solution for this?


"Ken Slovak - [MVP - Outlook]" wrote:

> Yes, that's the sort of LDAP query you'd need. Google is your friend for
> trying to find a C# example of an LDAP query.
>
> --
> Ken Slovak
> [MVP - Outlook]
> http://www.slovaktech.com
> Author: Professional Programming Outlook 2007.
> Reminder Manager, Extended Reminders, Attachment Options.
> http://www.slovaktech.com/products.htm
>
>
> "khai" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Are you referring to the following:
> > '*** Get the current User
> > Dim oWNetwork
> > Set oWNetwork = CreateObject("WScript.Network")
> > Set oRootDSE = GetObject("LDAP://RootDSE")
> > Set oMyDomain = GetObject("LDAP://" & _
> > oRootDSE.Get("defaultNamingContext"))
> > Set cnn = CreateObject("ADODB.Connection")
> > cnn.provider = "adsDSOObject"
> > cnn.Open oMyDomain.ADSPath
> > Set rst = CreateObject("ADODB.Recordset")
> >
> > '*** UserPath in AD
> > StrSQL = "SELECT adspath " &_
> > "FROM '" & oMyDomain.ADSPath & "'" & _
> > "WHERE SAMAccountName ='" & oWNetwork.UserName & "'"
> > rst.Open StrSQL, cnn
> > ADUserPath = rst.Fields("adspath")
> > Set ADAccount = GetObject(ADUserPath)
> >
> > '*** Users Data
> > Item.UserProperties.Find("UserName") = ADAccount.FullName
> > Item.UserProperties.Find("UserInitials") = ADAccount.initials
> > Item.UserProperties.Find("userPhone") = ADAccount.telephoneNumber
> >
> > Is there a C# version?
> >
> > "Ken Slovak - [MVP - Outlook]" wrote:
> >
> >> To query the AD directly you would need to use an LDAP query, assuming
> >> you
> >> have permissions to run that. Take a look at
> >> http://www.outlookcode.com/threads.a...messageid=3870 and also
> >> search on other links at www.outlookcode.com on "LDAP" for examples of
> >> how
> >> to do that.
> >>
> >> --
> >> Ken Slovak
> >> [MVP - Outlook]
> >> http://www.slovaktech.com
> >> Author: Professional Programming Outlook 2007.
> >> Reminder Manager, Extended Reminders, Attachment Options.
> >> http://www.slovaktech.com/products.htm
> >>
> >>
> >> "khai" <(E-Mail Removed)> wrote in message
> >> news:(E-Mail Removed)...
> >> > This works for getting the sender's account. But how can I get the
> >> > recipient's AD account?
> >> >
> >> > I have also noticed that in the Outlook address book, some of the
> >> > user's
> >> > email address (i.e. ... /cn=...) is not the same as the alias field. I
> >> > need
> >> > to get the user's AD account (i.e. login information) as I would like
> >> > to
> >> > programmatically assign the ACL based on the recipients list.
> >>
> >>

>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
getting rid of site & getting my desktop back? monkeynut33@charter.net Windows XP Security 1 1st Jul 2004 07:03 AM
Having Trouble getting on to Yahoo games getting a blank page =?Utf-8?B?SnVkaXNtYXJ0?= Windows XP Games 2 25th Jun 2004 06:41 AM
Netwok getting connection getting diconnected Ramaswamy Windows XP General 0 3rd Jan 2004 07:06 AM
Getting Rid of Search, Getting Find Instead Laura Windows XP Customization 3 30th Nov 2003 04:35 PM
Account Operators can't manage other Account Operators account Mikael Oskarsson Microsoft Windows 2000 Active Directory 2 22nd Aug 2003 07:12 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:12 PM.