所以我正在用 python 编写一个程序,它将报告与 RGS 连接的系统上的用户。
让用户使用 Windows 的一种方法是query session
命令。
我都尝试过os.popen
and subprocess.Popen
有壳和无壳=True。我什至指定了命令的完整路径。
我得到的只是这个错误:
'C:/Windows/System32/query.exe' is not recognized as an internal or external command, operable program or batch file.
我可以使用 PsLoggedon.exe 让它工作,但这不会告诉我会话类型。
所以我想我的问题是:如何让这个命令起作用,或者解决这个问题的另一种方法是什么?
import subprocess
args = ['C:\\Windows\\system32\\query.exe', 'user']
process = subprocess.Popen(args, stdout=subprocess.PIPE)
output, err = process.communicate()
users = [line[1:].split(' ')[0] for line in output.strip().split('\n')[1:]]
print(users)
Prints ['poke']
for me.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)