如何在Windows Server 2008的MS Access VBA中获取Windows用户名 [英] How to get windows username in MS Access VBA on Windows Server 2008

查看:95
本文介绍了如何在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://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

这篇关于如何在Windows Server 2008的MS Access VBA中获取Windows用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆