Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to receive cmd 'quser' output?

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
like image 865
Ohav Avatar asked Oct 15 '25 14:10

Ohav


1 Answers

subprocess.check_output(r"C:\Windows\Sysnative\quser.exe")

really worked.

like image 129
matebende Avatar answered Oct 18 '25 03:10

matebende



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!