Jump to content

Get remote SESSIONAME to StdoutRead, for logoff purpose


jmoreira
 Share

Recommended Posts

Hi,

I'm trying to get remote SESSIONNAME to StdoutRead, for logoff purpose using qwinsta | findstr and cut (from http://unxutils.sourceforge.net/). It works in command prompt but can't get it in script.

Help is needed, anyone have a clue?

(code below)

#include <Constants.au3>

Local $server="server", $domain="domain", $user="user", $password="passwd"

$var = 'qwinsta.exe '&$user&' /server:'&$server&' | findstr rdp | cut -c2-11'
; result should be: rdp-tcp#0 

MsgBox(0, "STDOUT read:", _getDOSOutput($var))
; but nothing appears in MsgBox

Runwait(@ComSpec & " /c " & 'logoff '&_getDOSOutput($var)&' /SERVER:'&$server&'', "", @SW_HIDE)

Func _getDOSOutput($command)
    Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4)
    While 1
            $text &= StdoutRead($Pid, False, False)
            If @error Then ExitLoop
            Sleep(10)
    WEnd
    Return StringStripWS($text, 7)
EndFunc   ;==>_getDOSOutput
Link to comment
Share on other sites

Hi jmoreira

if there is an error in the command in $var in line 5, then you do not see the output because you do not fetch the StdErr

in line 14 try adding +8  ($STDERR_MERGED) to capture even the error messages with StdoutRead()

Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4 + 8)
Edited by PincoPanco

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...