How to retrieve Windows userID in VB for 64-bit/Access 2013?

只愿长相守 提交于 2020-04-11 11:46:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!