如何在Windows Server 2008的MS Access VBA中获取Windows用户名

问题描述:

我在MS Access VBA中使用以下代码: 如何在Access vba中获得登录用户名?

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

它工作得很好. 但是,我们的外籍员工需要在服务器上使用该软件,并且无法检索用户名. 我们照常登录. 服务器版本为Windows Server 2008 SP2.

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.

有什么建议吗?

最诚挚的问候,埃米尔.

Best regards, Emil.

我不知道您正在使用哪种方法(有几个答案),但是HansUp建议的这一方法既简单又容易希望也可以在服务器上工作:

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://*.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