?
Solved

Use API LookupAccountSid to find outlook phone number

Posted on 2004-08-04
7
Medium Priority
?
364 Views
Last Modified: 2008-03-17
Hi,

I have the below code which works fine but I would also like to get the persons telephone number from outlook.

Option Explicit
Private Declare Function LookupAccountSid Lib "advapi32.dll" Alias "LookupAccountSidA" (ByVal lpSystemName As String, Sid As Any, ByVal name As String, cbName As Long, ByVal ReferencedDomainName As String, cbReferencedDomainName As Long, peUse As Integer) As Long

Public Function LookUpUserByOutlookSID(ByVal strSID As String)
Dim bByte() As Byte
Dim tmp As Integer
Dim i As Integer
Dim ret As Boolean
Dim strDomain As String
Dim iType As Integer
Dim strUserId As String
Dim strFname As String
Dim strLname As String
Dim strEmail As String
Dim strPhone As String
Dim strPersonId As string

On Error GoTo errOutlook:

tmp = Len(strSID) / 2 - 1
ReDim bByte(tmp) As Byte
For i = 0 To tmp - 1
  bByte(i) = CInt("&h" & Mid(strSID, (i * 2) + 1, 2))
Next

strUserId = Space(64)
strDomain = Space(64)

'Get the NT Domain and UserName
ret = LookupAccountSid(vbNullString, bByte(0), strUserId, Len(strName), strDomain, Len(strDomain), iType)
 
strDomain = Left(strDomain, InStr(strDomain, Chr(0)) - 1)
strUserId = Left(strUserId, InStr(strUserId, Chr(0)) - 1)
strPersonId = strUserId

End Function


Thanks for any help

Damien
0
Comment
Question by:damienm
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 11722598
I don't think that you can get that information that way.  Do you have access to Active Directory services?

Bob
0
 
LVL 2

Author Comment

by:damienm
ID: 11724440
Do you have any code for this?

Thanks,

Damien
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 500 total points
ID: 11725835
Include a reference to Active DS TypeLib.

Dim oUser As IADsUser
           
Set oUser = GetObject("WinNT://<domain/name>,user")

sNumber = oUser.TelephoneNumber

This only works if you use this property in Active Directory.

Bob
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 12469858
Thanks Dan, it is nice sometimes to be the rewardee, instead of the rewarder.

Bob
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question