问题
I need to get code to retrieve the Windows userID for the current session in VB (for Access 2013) on a 64-bit system.
I've tried the solution suggested at How to get logged-in user's name in Access vba?, but apparently this doesn't work on my 64-bit machine. I've also tried to figure out how to integrate the info at http://msdn.microsoft.com/en-us/library/office/gg278832.aspx, but I can't figure it out.
I am a NOVICE VB programmer, so I really need the actual code to do this. (I can [probably] figure out how & why the code does what it does after I see it, but I can't come up with it from scratch at this point.)
I'm hoping this answer will be helpful to others, too.
Thanks so much!
Aloha, -pt
回答1:
The answer you linked to works on a 32 bit version of access. For 64 bit versions, you need to use a pointer-safe signature:
Private Declare PtrSafe Function GetUserName Lib "advapi32.dll" Alias
"GetUserNameA" (ByVal lpBuffer As String, nSize As LongPtr) As Long
(it might work with nSize As Long
- I don't have a 64-bit access at hand)
回答2:
This should work, too:
Dim wshNet As Object
Set wshNet = CreateObject("WScript.Network")
MsgBox "Hello, " & wshNet.UserName & "!"
Set wshNet = Nothing
来源:https://stackoverflow.com/questions/16847583/how-to-retrieve-windows-userid-in-vb-for-64-bit-access-2013