How to get windows username in MS Access VBA on Windows Server 2008

穿精又带淫゛_ 提交于 2019-12-31 05:13:06

问题


I am using this code in my MS Access VBA: How to get logged-in user's name in Access vba?

It works perfectly fine. However, our foreign employees need to use the software on a server, and it is unable to retrieve the username. We are signed in as usual. The server version is Windows Server 2008 SP2.

Any suggestions?

Best regards, Emil.


回答1:


I don't know which method you are using (there are several answers), but this one suggested by HansUp is easy and hopefully works on the Server too:

https://stackoverflow.com/a/32565953/3820271

Public Function GetUserName() As String
    ' GetUserName = Environ("USERNAME")
    ' Better method, see comment by HansUp
    GetUserName = CreateObject("WScript.Network").UserName
End Function


来源:https://stackoverflow.com/questions/34352511/how-to-get-windows-username-in-ms-access-vba-on-windows-server-2008

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