Your trouble is in name of executable. Single backslash works just as escape character, so if you would print name of the command you are going to start, you would see the backslashes being lost.
The options are:
cmd = r"D:\pstools\psloggedon.exe" # raw string prefix r
print cmd
cmd = "D:\\pstools\\psloggedon.exe" # double backslash
print cmd
cmd = "D:/pstools/psloggedon.exe" # forward slash works also on windows
print cmd
You may try using following idiom, which allows better detection of problems
userIP="\\\\"+userIP
cmd = ["D:\\pstools\\psloggedon.exe"]
cmd.extend(["-l", "-x", userIP])
print "cmd", cmd # do it only, if you are developing
pst = subprocess.Popen(
cmd,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE
)
This allows you to print out cmd
and see, if there are possible problems visible.
note: the code above builds on the accepted answer solution (which adds solution for proper userIP
but might have problems with backslashes).