如何使用Python检索当前Windows用户名(AD或本地)? [英] How to Retrieve name of current Windows User (AD or local) using Python?

查看:201
本文介绍了如何使用Python检索当前Windows用户名(AD或本地)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用python脚本检索当前登录用户的名称?不管它是域/广告用户还是本地用户,该功能都应起作用。

How can I retrieve the name of the currently logged in user, using a python script? The function should work regardless of whether it is a domain/ad user or a local user.

推荐答案

尝试以下操作:

import os;
print os.environ.get( "USERNAME" )

这应该可以完成工作。

That should do the job.

这篇关于如何使用Python检索当前Windows用户名(AD或本地)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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