TranslateName Function/API Call?

J

James

I would like to get a user's first name and last name instead of just their
username. According to this link,

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/sysinfo/base/translatename.asp

there is a function that will do that if I use the NameDisplay member of
the Extended_Name_Format enumeration in the function call, but I can't
figure out how to implement it in VB. It seems to be an API call, but I
can't find an acceptable Declare for it. I've googled the web and Usenet
and can't find much documentation.

Any help would be appreciated.

Thanks,

James
 
T

Tom Shelton

I would like to get a user's first name and last name instead of just their
username. According to this link,

http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/sysinfo/base/translatename.asp

there is a function that will do that if I use the NameDisplay member of
the Extended_Name_Format enumeration in the function call, but I can't
figure out how to implement it in VB. It seems to be an API call, but I
can't find an acceptable Declare for it. I've googled the web and Usenet
and can't find much documentation.

Any help would be appreciated.

Thanks,

James

AirCode!

<Flags()> _
Public Enum EXTENDED_NAME_FORMAT
NameUnknown = 0
NameFullyQualifiedDN = 1
NameSamCompatible = 2
NameDisplay = 3
NameUniqueId = 6
NameCanonical = 7
NameUserPrincipal = 8
NameCanonicalEx = 9
NameServicePrincipal = 10
NameDnsDomain = 12
End Enum

Public Declare Auto Function TranslateName Lib "secur32" _
(ByVal lpAccountName As String, _
ByVal AccountNameFormat As EXTENDED_NAME_FORMAT, _
ByVal DesiredNameFormat As EXTENDED_NAME_FORMAT, _
ByVal lpTranslatedName As System.Text.StringBuilder, _
ByRef nSize As Integer) As Boolean

Dim translatedName As New StringBuilder(256)
Dim nSize As Integer = translatedName.Capacity

If Not TranslateName( _
"TheAccountName",
EXTENDED_NAME_FORMAT.NameSamCopatible, _
EXTENDED_NAME_FORMAT.NameDisplay, _
translatedName, _
nSize) Then

Dim ex As New _
System.ComponentModel.Win32Exception( _
Marshal.GetLastWin32Error())
MessageBox.Show(ex.Message)
Else
MessageBox.Show(translatedName.ToString())
End If

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top