I am trying to build Python code that will run the quser program in cmd and will receive the output of it to then run log off to one of the users.
I tried to do it both with os
and subprocess
modules in Python 3.7.3, but it seems like it always says:
'quser' is not recognized as an internal or external command.
I have also tried a full path to the quser
executable.
import os
import subprocess
output = os.system("quser")
print(output)
# returns -- > 'quser' is not recognized as an internal or external command, operable program or batch file.
p = subprocess.Popen("quser", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
print(out)
# returns -- > 1 b''
Expected Output
USERNAME SESSIONNAME ID STATE IDLETIME LOGON TIME
John console 1 Active 57 19/07/2019 12:27
Doe 2 Disc 57 19/07/2019 15:35
subprocess.check_output(r"C:\Windows\Sysnative\quser.exe")
really worked.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With