Solved

Use API LookupAccountSid to find outlook phone number

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

809 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