Rails 获取当前登录的 Windows 用户的用户名 [英] Rails get username of currently logged windows user
本文介绍了Rails 获取当前登录的 Windows 用户的用户名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要获取当前登录的 Windows 用户的用户名.可以轻松完成吗?
I need to get the username of the currently logged windows user. Could it be done easily?
推荐答案
可以通过以下方式访问运行脚本的帐户的用户名:
The username of the account running the script can be accessed via something like:
放入 ENV['USERNAME']
请注意,如果您将其作为系统服务运行,则用户名可能会返回为SYSTEM"
Beware that if you're running it as a system service the username will probably come back as "SYSTEM"
如果这还不足以满足您的需求,这里列出了另一种方法:https://stackoverflow.com/a/3544741/648695
If that isn't enough to suite your needs there is an alternative method outlined here: https://stackoverflow.com/a/3544741/648695
这篇关于Rails 获取当前登录的 Windows 用户的用户名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文