环境(“用户名”)与 advapi32.dll
我知道至少有两种方法可以在 Access 应用程序中检索用户名。
您可以使用environ函数:
environ("username")
并且您可以在advapi32.dll中使用GetUsername
Public Declare Function GetUserName& Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long)
s = String(l, Chr(32))
GetUserName s, l
username = Left$(s, l - 1)
上述哪一种方法使用起来最安全?为什么?
也许有一些背景信息,这些应用程序既可以在本地计算机上使用,也可以在远程桌面上使用。
I know there are at least 2 ways of retrieving the username in an Access application.
You can use the environ function:
environ("username")
And you can use GetUsername in advapi32.dll
Public Declare Function GetUserName& Lib "advapi32.dll" Alias _
"GetUserNameA" (ByVal lpBuffer As String, nSize As Long)
s = String(l, Chr(32))
GetUserName s, l
username = Left$(s, l - 1)
Which one of the above methods is the safest to use? And why?
Perhaps some background info, the applications are used both on the local computers and remote desktops.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如 Simon 所说,环境变量可以进行操作,但是有些人也喜欢避免 api 调用,如果是这种情况,那么这是一个简单易行的替代方案:
As Simon has said, Environ variables are open to manipulation, however some people also like to avoid the api calls, if this is the case then this is a simple to follow alternative:
任何人都可以设置和取消环境变量、丢失等等,如果有人认为它是错误来源,那么这些情况往往很难重现。
我肯定会选择 advapi。
Environment variables can be set and unset by anyone, go missing and whatnot, and these cases tend to be difficult to reproduce if anyone even thinks of it as a source of errors.
I'd definitely go with advapi.