Search code examples
pythonmultithreadingoperating-system

can't call qwinsta with pythonw


I'm trying to build an application which uses the wx module for the graphical part. My operating system is windows 10 and the python version is 2.7.

This application should check if someone is remote connected to the computer and change the color of a button if so. To check if someone is connected to the computer, i parse the output of the qwinsta call.

I have to specify this: to run this application i use pythonw.

The code block is the following:

def isLocked():
    process =subprocess.Popen('qwinsta',stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
    output,error = process.communicate()
    print output
    output2 = output[0:len(output)]

    output2= output2.split('\n')

The problem is that, the subprocess call i made returns an error:

'qwinsta' is not recognized as an internal or external command,\r\noperable program or batch file.\r\n"""

I think i found the problem but i don't know how to solve it:

This subprocess call works fine if i would call it with python. If i use pythonw it fails. To me it seems like pythonw uses the syswow64/cmd.exe, and python uses the system32/cmd.exe.

I checked the os.environ variable on both python and pythonw and the COMSPEC variable is the same.


Solution

  • So i found a work around the problem. I still think the problem was that the pythonw uses the windows/syswow64/cmd.exe . This cmd seems to be unable to execute the qwinsta.exe executable which is found in the Syste32 folder.

    *But this qwista.exe is also found in the windows/WinSxS folder, where the syswow64/cmd.exe has access and is able to run the executable.

    The work around was that, i gave to the subprocess Popen the path to the windows/WinSxS/amd64_microsoft-windows-t..commandlinetoolsmqq_31bf3856ad364e35... qwinsta.exe

    process =subprocess.Popen('',stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=False,executable='C:\Windows\WinSxS\amd64...\qwinsta.exe')