Jump to content
Sign in to follow this  
Vykaendys

Issue reading command line console output

Recommended Posts

Vykaendys

Hi all,

     I've been scouring the forums trying to find an answer to this, and I'm completely stumped.  I'm trying to read the console output from the 'change.exe' command.  I've used StdOutRead before successfully, but I just can't get it to read the output from this command.

Using the 'qwinsta' command, I get output in this code:

#include <Constants.au3>

Local $CMDREAD

$PID = Run(@ComSpec & ' /c qwinsta', "", "", $STDERR_CHILD + $STDOUT_CHILD)
Do
    $CMDREAD &= StdoutRead($PID, False, False)
Until Not ProcessExists($PID)
$CMDREAD &= StdoutRead($PID, False, False)
ConsoleWrite("|" & $CMDREAD & "|" & @CRLF)

This provides the output:

| SESSIONNAME       USERNAME                 ID  STATE   TYPE        DEVICE
 services                                    0  Disc                        
>console           swarner                   1  Active                      
 rdp-tcp                                 65536  Listen                      
|

If I throw in the change command as:

#include <Constants.au3>

Local $CMDREAD

$PID = Run(@ComSpec & ' /c change logon /query', "", "", $STDERR_CHILD + $STDOUT_CHILD)
Do
    $CMDREAD &= StdoutRead($PID, False, False)
Until Not ProcessExists($PID)
$CMDREAD &= StdoutRead($PID, False, False)
ConsoleWrite("|" & $CMDREAD & "|" & @CRLF)

The output I get is:

||

If I change $STDERR_CHILD + $STDOUT_CHILD to $STDIO_INHERIT_PARENT I can see the output I need in the SciTE console:

"Connections are currently ENABLED by Group Policy for this machine, unable to change." but $CMDREAD is still blank.

I've tried different opt_flags in the run command, changing peek to true in the stdoutread, modifying how the command is called (with or without @comspec, different cmd switches, etc).  I'm at a complete loss as to how to get that output into a variable so I can work with it.

Any help would be greatly appreciated.

Share this post


Link to post
Share on other sites
Chimp

Iit seems an "filesystem redirection" problem.
have a look >here for info

try in this way: (modified lines are marked with ; <--)
 

#include <Constants.au3>

Local $CMDREAD
_Wow64FsRedirection(False) ; <---
$PID = Run(@ComSpec & ' /c change logon /query', "", "", $STDERR_MERGED) ; <---
_Wow64FsRedirection(True) ; <---
Do
    $CMDREAD &= StdoutRead($PID, False, False)
Until @error ; Not ProcessExists($PID) ; <---
; $CMDREAD &= StdoutRead($PID, False, False) ; <---
ConsoleWrite("|" & $CMDREAD & "|" & @CRLF)

Func _Wow64FsRedirection($state) ; <--
    ; Disables or reverts the filesystem redirector for a 32 bit process running on 64bit OS
    If Not @AutoItX64 And @OSArch = 'X64' Then
        If $state Then
            DllCall("kernel32.dll", "int", "Wow64RevertWow64FsRedirection", "int", 0)
        Else
            DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 0); or 1 as per help
        EndIf
        If @error Then Return SetError(1)
    EndIf
EndFunc   ;==>_Wow64FsRedirection

edit:

modified second _Wow64FsRedirection(False) to _Wow64FsRedirection(True)

Edited by PincoPanco

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

Share this post


Link to post
Share on other sites
Vykaendys

I'm running this all on a 32-bit system, so it's not that.

I was able to get the data I need using WMIC instead, but I would still like to know how to read that input.

Share this post


Link to post
Share on other sites
Chimp

it works for me on my system win7 x64.

if I run it without the Wow64FsRedirection lines I get an dos error "change" unrecognized command,

if I run with the Wow64FsRedirection then it works.

What do you get as output if you run my  modified script, as is, and commenting out the two lines Wow64FsRedirection( before and after the $PID = Run( command?


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

Share this post


Link to post
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
Sign in to follow this  

×