Solved

Use API LookupAccountSid to find outlook phone number

Posted on 2004-08-04
7
332 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
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…
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…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now