|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
Get XP Descriptive User Name with VB6
I'm stuck... I can get the XP user name (logon ID) and the domain name, but I can't figure out how to get the account's descriptive name from the system.
Very frustrated - I'm trying to build a class in VB6 which will contain all the basic system properties (computer name, IP, logged in user ID, domain (if any), etc). If anyone knows how to do this last bit then I'll happily post the class here for all to use. Thanks in advance if you have any ideas! |
|
#2
|
|||
|
|||
|
U can realize it with API.
|
|
#3
|
|||
|
|||
|
How? I use the API and function below to get the local User ID (logon name), but I do not see how you can get their Full Text name - do you have the code for this?
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long Public Function localUserName() As String Dim m_myBuf As String * 25 Dim m_Val As Long, UserName As String m_Val = GetUserName(m_myBuf, 25) localUserName = Left(m_myBuf, InStr(m_myBuf, Chr(0)) - 1) End Function |
|
#5
|
|||
|
|||
|
Thanks - I'll take a look at it and let you guys know.
|
|
#6
|
|||
|
|||
|
Nice Tools-API-Guide!http://www.student.kuleuven.ac.be/~...3.7/agsetup.exe
This is API-Guide's Sample code: Private Enum EXTENDED_NAME_FORMAT NameUnknown = 0 NameFullyQualifiedDN = 1 NameSamCompatible = 2 NameDisplay = 3 NameUniqueId = 6 NameCanonical = 7 NameUserPrincipal = 8 NameCanonicalEx = 9 NameServicePrincipal = 10 End Enum Private Declare Function GetUserNameEx Lib "secur32.dll" Alias "GetUserNameExA" (ByVal NameFormat As EXTENDED_NAME_FORMAT, ByVal lpNameBuffer As String, ByRef nSize As Long) As Long Private Sub Form_Load() 'KPD-Team 2001 'URL: http://www.allapi.net/ 'E-Mail: KPDTeam@allapi.net Dim sBuffer As String, Ret As Long sBuffer = String(256, 0) Ret = Len(sBuffer) If GetUserNameEx(NameSamCompatible, sBuffer, Ret) <> 0 Then MsgBox "Username: " + Left$(sBuffer, Ret) Else MsgBox "Error while retrieving the username" End If End Sub |
|
#7
|
|||
|
|||
|
Thanks for the code, but it still only returns the logged in UserID - this time with the domain. There is a "Full Text" property of the user account, as evidenced by the Start Menu in XP Pro.
Is it possible to extract the name from the start menu? That would at least be a functional workaround for now. I'm trying to validate the username against an exchange mail server, and the persons "full text" name matches the name they are represented by in the email system... |
|
#8
|
|||
|
|||
|
Yes!ajmh!This code is useful to U!
Option Explicit 'Windows type used to call the Net API Private Type USER_INFO_10 usr10_name As Long usr10_comment As Long usr10_usr_comment As Long usr10_full_name As Long End Type 'private type to hold the actual strings displayed Private Type USER_INFO name As String fullname As String comment As String usrcomment As String End Type Private Const ERROR_SUCCESS As Long = 0& Private Const MAX_COMPUTERNAME As Long = 15 Private Const MAX_USERNAME As Long = 256 Private Declare Function NetUserGetInfo Lib "netapi32" _ (lpServer As Byte, _ username As Byte, _ ByVal Level As Long, _ lpBuffer As Long) As Long Private Declare Function NetApiBufferFree Lib "netapi32" _ (ByVal Buffer As Long) As Long Private Declare Function GetUserName Lib "advapi32" _ Alias "GetUserNameA" _ (ByVal lpBuffer As String, _ nSize As Long) As Long Private Declare Function GetComputerName Lib "kernel32" _ Alias "GetComputerNameA" _ (ByVal lpBuffer As String, _ nSize As Long) As Long Private Declare Sub CopyMemory Lib "kernel32" _ Alias "RtlMoveMemory" _ (xDest As Any, _ xSource As Any, _ ByVal nBytes As Long) Private Declare Function lstrlenW Lib "kernel32" _ (ByVal lpString As Long) As Long Private Declare Function StrLen Lib "kernel32" _ Alias "lstrlenW" _ (ByVal lpString As Long) As Long Private Sub Form_Load() Text1.Text = rgbGetUserName() Text2.Text = rgbGetComputerName() End Sub Private Sub Command1_Click() Dim usr As USER_INFO Dim bUsername() As Byte Dim bServername() As Byte Dim tmp As String 'This assures that both the server 'and user params have data. Must 'perform actual comparisons to 0 since 'results such as "2 And 5" equate to False! If Len(Text1.Text) > 0 And Len(Text2.Text) > 0 Then bUsername = Text1.Text & Chr$(0) 'This demo uses the current machine as the 'server param, which works on NT4 and Win2000. 'If connected to a PDC or BDC, pass that 'name as the server, instead of the return 'value from GetComputerName(). tmp = Text2.Text 'assure the server string is properly formatted If Len(tmp) > 0 Then If InStr(tmp, "\\") Then bServername = tmp & Chr$(0) Else: bServername = "\\" & tmp & Chr$(0) End If End If 'Return the user information for the passed 'user. The return values are assigned directly 'to the non-API USER_INFO data type that we 'defined (I prefer UDTs). Alternatively, if 'you're a 'classy' sort of guy, the return 'values could be assigned directly to properties 'in the function. usr = GetUserNetworkInfo(bServername(), bUsername()) Text3.Text = usr.name 'The call may or may not return the 'full name, comment or usrcomment 'members, depending on the user's 'listing in User Manager. Text4.Text = usr.fullname Text5.Text = usr.comment Text6.Text = usr.usrcomment End If End Sub Private Function rgbGetComputerName() As String 'return the name of the computer Dim tmp As String tmp = Space$(MAX_COMPUTERNAME + 1) If GetComputerName(tmp, Len(tmp)) <> 0 Then rgbGetComputerName = TrimNull(tmp) End If End Function Private Function TrimNull(item As String) Dim pos As Integer pos = InStr(item, Chr$(0)) If pos Then TrimNull = Left$(item, pos - 1) Else: TrimNull = item End If End Function Private Function rgbGetUserName() As String 'return the name of the user Dim tmp As String tmp = Space$(MAX_USERNAME) If GetUserName(tmp, Len(tmp)) Then rgbGetUserName = TrimNull(tmp) End If End Function Private Function GetUserNetworkInfo(bServername() As Byte, _ bUsername() As Byte) As USER_INFO Dim usrapi As USER_INFO_10 Dim buff As Long If NetUserGetInfo(bServername(0), bUsername(0), 10, buff) = ERROR_SUCCESS Then 'copy the data from buff into the 'API user_10 structure CopyMemory usrapi, ByVal buff, Len(usrapi) 'extract each member and return 'as members of the UDT GetUserNetworkInfo.name = GetPointerToByteStringW(usrapi.usr10_name) GetUserNetworkInfo.fullname = GetPointerToByteStringW(usrapi.usr10_full_name) GetUserNetworkInfo.comment = GetPointerToByteStringW(usrapi.usr10_comment) GetUserNetworkInfo.usrcomment = GetPointerToByteStringW(usrapi.usr10_usr_comment) NetApiBufferFree buff End If End Function Private Function GetPointerToByteStringW(lpString As Long) As String Dim buff() As Byte Dim nSize As Long If lpString Then 'its Unicode, so mult. by 2 nSize = lstrlenW(lpString) * 2 If nSize Then ReDim buff(0 To (nSize - 1)) As Byte CopyMemory buff(0), ByVal lpString, nSize GetPointerToByteStringW = buff End If End If End Function |
|
#9
|
|||
|
|||
|
thank you thank you thank you
cleverpigVery much appreciated! - Ok - now the first problem is solved! Now I have another, associated problem: The users which I am attempting to get the details for are actually just members of the administrators group (they will always have admin access) - but they don't have an individual local account. Any ideas? If no then I'm still many steps closer to what I'm looking for. |
|
#10
|
|||
|
|||
|
U can use above program!It's effective!
Plz input the "\\" & UserIP(User localed at it) into the text2,U can get the User's group.Pay attention to Having the admin access right! |
|
#11
|
|||
|
|||
|
cleverpig,
I have tried as you say, but I cannot get it to work. Your code makes sure there is "\\" in front of the user's computer or ip (both of which work, thanks for that info). My problem is that the user's Logon ID is mapped to a domain (see example below), and while the program returns the details for a local account, it doesn't seem to work on groups or individuals in those groups (unless they have a local account). Example: UserID: AJMH Domain: myComputer This would output: \\myComputer\AJMH But the User "AJMH" is only a member of "Administrators" group on the local PC - there is no "User" account called "AJMH", so while the logged on user is being reported as "AJMH" with the domain "myComputer" or ip address "127.0.0.1" (or whatever the local address happens to be) it will not bring up the extra details. If, however, I use the following details, which link to a local account, then it works perfectly. UserID: Administrator Domain: myComputer -OR- myIPAddress ...am I making more sense, or do I not understand?? |
|
#12
|
|||
|
|||
|
Obtaining a Network User's Full Name and Comments:
http://www.mvps.org/vbnet/index.htm...usergetinfo.htm |
|
#13
|
|||
|
|||
|
yes, you are very right - I figured it out last night but didn't have a chance to post it here. My problem was that I needed to feed the logon server as the computer name / domain name rather than the local machine. I have also determined that you can find the name of the logon server being used in the "Volatile" information of the registry HKEY_LOCAL_USER.
Thanks very much for your help + patience with me not getting it ![]() |
|
#14
|
|||
|
|||
|
No Thanks!
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Visual Basic Programming > Get XP Descriptive User Name with VB6 |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|