> Can anyone help me to retrieve the Full Name?
Try this link.
[ http://www.mvps.org/access/api/api0066.htm ]
Although it's written for Access, you shouldn't have any problems porting
it to Excel.
-- Dev
Dev Ashish <d...@nomail.please> wrote in message
news:Xns9106B04CA86A5...@207.46.230.185...
I have tried out the code and works.
I have added a text inside the pserver variable that took
me a bit to figure out.
Hope it helps.
Justin
>-----Original Message-----
>Dear All
>I would like to retrieve the NT Domain User's Full Name
using a macro, ---
'USER_INFO_3 structure is defined in Win32 SDK,
below is the VB
'declare.
'LPWSTR is a pointer to a Unicode string.
'The storage of the USER_INFO_3 structure,
including the string
'buffer referred by its LPWSTR members, are all
allocated by Windows
'NT so the function caller doesn't have to allocate
memory.
Private Type USER_INFO_3
usri3_name As Long 'LPWSTR in SDK
usri3_password As Long 'LPWSTR in SDK
usri3_password_age As Long 'DWORD in SDK
usri3_priv As Long 'DWORD in SDK
usri3_home_dir As Long 'LPWSTR in SDK
usri3_comment As Long 'LPWSTR in SDK
usri3_flags As Long 'DWORD in SDK
usri3_script_path As Long 'LPWSTR in SDK
usri3_auth_flags As Long 'DWORD in SDK
usri3_full_name As Long 'LPWSTR in SDK
usri3_usr_comment As Long 'LPWSTR in SDK
usri3_parms As Long 'LPWSTR in SDK
usri3_workstations As Long 'LPWSTR in SDK
usri3_last_logon As Long 'DWORD in SDK
usri3_last_logoff As Long 'DWORD in SDK
usri3_acct_expires As Long 'DWORD in SDK
usri3_max_storage As Long 'DWORD in SDK
usri3_units_per_week As Long 'DWORD in SDK
usri3_logon_hours As Long 'PBYTE in SDK
usri3_bad_pw_count As Long 'DWORD in SDK
usri3_num_logons As Long 'DWORD in SDK
usri3_logon_server As Long 'LPWSTR in SDK
usri3_country_code As Long 'DWORD in SDK
usri3_code_page As Long 'DWORD in SDK
usri3_user_id As Long 'DWORD in SDK
usri3_primary_group_id As Long 'DWORD in SDK
usri3_profile As Long 'LPWSTR in SDK
usri3_home_dir_drive As Long 'LPWSTR in SDK
usri3_password_expired As Long 'DWORD in SDK
End Type
Private Declare Function NetUserGetInfo
Lib "netapi32.dll" ( _
strServerName As Any, strUserName As Any, ByVal
dwLevel As Long, _
pBuffer As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32"
Alias "RtlMoveMemory" _
(hpvDest As Any, ByVal hpvSource As Long, ByVal
cbCopy As Long)
Private Sub Command1_Click()
Dim pServer() As Byte, pUser() As Byte
'You need to change "Your_Domain_Logon_Name" in
the next line
'to your valid NT domain logon name.
pUser = "Place your user id here" & vbNullChar
pServer = "\\ + your server or domain here" &
vbNullChar
'The above two lines convert VB string to
Unicode string.
Dim dwLevel As Long
dwLevel = 3
Dim tmpBuffer As USER_INFO_3
Dim ptmpBuffer As Long
Debug.Print NetUserGetInfo(pServer(0), pUser(0),
dwLevel, ptmpBuffer)
'As last param is dimmed as long, the pointer to
ptmpBuffer is
'passed to dll, and the function returns a
pointer to a pointer
'to our UDT. Therefore ptmpBuffer on return
holds a pointer
'to our UDT.
'Deference it!!!
CopyMemory tmpBuffer, ptmpBuffer, LenB(tmpBuffer)
Dim sUser As String
Dim sByte() As Byte
ReDim sByte(255)
'Convert LPWSTR (Unicode string) to VB string.
CopyMemory sByte(0), tmpBuffer.usri3_full_name,
256
sUser = sByte
sUser = sUser & vbNullChar
MsgBox Trim$(sUser)
'Now I get my user name back, it's VB string now'
End Sub
Justin Gilbert <JDGi...@mcleodusa.com> wrote in message
news:11f2301c12cca$dd21cb80$a4e62ecf@tkmsftngxa06...
These are structures written in C or C++. The definitions expect a certain
amount of memory to be allocated for these. Although you may not use all of
them, the API will populate them. As a result, they need to be completed.
In this case, the API creates its own structure and returns a pointer.
Secondly, the items are positional. What that means is that when the record
is populated, they hold a specific place in memory. Each of the variables
declarations is an offset into that memory.
Here's an simple example. Consider the three fields. (note that I am not
doing byte swapping and this is only for illustration)
Type MyType
A As Long
B As Long
C As Long
End Type
This would be 'XXXXyyyyZZZZ' of memory.
A = XXXX
B = YYYY
C = ZZZZ
I put 1234 in A 5566 in B and 7788 in C.
If I dropped B from the type structure, and the API returned its proper
structure and I copied the entire structure, then 5566 would be put in
variable C instead of the expected 7788. In addition, the data would be put
into memory position YYYY instead of ZZZZ.
Because the structure being returned expects 12 bytes and you only have 8,
the copy would not have the memory location to put 7788 and may get an abend
or GPF.
Hope this helps.
Justin
"Steve" <stevebl...@openlink.org> wrote in message
news:OBPANPBMBHA.1932@tkmsftngp05...
Thanks for that clear and concise explanation, Justin, it helped a lot.
Steve