Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
[COLOR=blue]
Option Explicit
' Utility function declares
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function lstrlenW Lib "kernel32" (lpString As Any) As Long
Private Declare Function NetUserGetInfo Lib "Netapi32.dll" (lpServer As Any, Username As Byte, ByVal Level As Long, lpBuffer As Long) As Long
Private Declare Function NetApiBufferFree Lib "netapi32" (ByVal Buffer As Long) As Long
' Declaration up to USER_INFO_3 here,
' but we are only using up to USER_INFO_2
Private Type USER_INFO_2
' Level 0 starts here
Name As Long
' Level 1 starts here
Password As Long
PasswordAge As Long
Privilege As Long
HomeDir As Long
Comment As Long
Flags As Long
ScriptPath As Long
' Level 2 starts here
AuthFlags As Long
FullName As Long
UserComment As Long
Parms As Long
Workstations As Long
LastLogon As Long
LastLogoff As Long
AcctExpires As Long
MaxStorage As Long
UnitsPerWeek As Long
LogonHours As Long
BadPwCount As Long
NumLogons As Long
LogonServer As Long
CountryCode As Long
codepage As Long
' Level 3 starts here, but we are not using
' UserID As Long
' PrimaryGroupID As Long
' Profile As Long
' HomeDirDrive As Long
' PasswordExpired As Long
End Type
Private Sub Command1_Click()
MsgBox vbGetFullUserName("Username")
End Sub
Public Function vbGetFullUserName(strName As String) As String
Dim myInfo As USER_INFO_2
Dim Username() As Byte
Dim buff As Long
Username = strName + Chr(0) ' API needs it to be null terminated
NetUserGetInfo 0&, Username(0), 2, buff
CopyMemory myInfo, ByVal buff, Len(myInfo) ' Copy from buffer into UDT
NetApiBufferFree ByVal buff ' be good and free allocated memory
vbGetFullUserName = GetStrFromPtrW(myInfo.FullName)
End Function
' Returns an ANSI string from a pointer to a Unicode string.
' (highly modified version of function from AllAPI.net)
Public Function GetStrFromPtrW(lpszW As Long) As String
Dim sRtn As String
sRtn = String$(lstrlenW(ByVal lpszW) * 2, 0) ' 2 bytes/char
CopyMemory ByVal sRtn, ByVal lpszW, Len(sRtn)
GetStrFromPtrW = StrConv(sRtn, vbFromUnicode)
End Function
[/color]