Kayleigh
Member
- Local time
- Today, 07:49
- Joined
- Sep 24, 2020
- Messages
- 709
Hi,
Would anyone be able to help me with re-writing this bit of code so it works on both 32-bit and 64-bit machines. It will currently not run on my 64-bit processor...
Thank you!
Would anyone be able to help me with re-writing this bit of code so it works on both 32-bit and 64-bit machines. It will currently not run on my 64-bit processor...
Code:
Option Compare Database
Option Explicit
'Return computer user name
Private Declare Function apiGetUserName Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
Function UserName() As String
' Returns the network login name
Dim lngLen As Long, lngX As Long
Dim strUserName As String
strUserName = String$(254, 0)
lngLen = 255
lngX = apiGetUserName(strUserName, lngLen)
If lngX <> 0 Then
UserName = left$(strUserName, lngLen - 1)
Else
UserName = ""
End If
End Function
Thank you!