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
Solved

Use API LookupAccountSid to find outlook phone number

Posted on 2004-08-04
7
344 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
  • 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 125 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

860 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