argumentum Posted December 1, 2018 Posted December 1, 2018 (edited) ..trying to run qwinsta and capture the output, I mean, I can do it from the command prompt but not from code. It tells me 'C:\Windows\System32\qwinsta.exe' is not recognized as an internal or external command but the file is there !. #include <AutoItConstants.au3> Example() Func Example() Local $iPID = Run(@ComSpec & " /c C:\Windows\System32\qwinsta.exe", @SystemDir, @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf WEnd While 1 $sOutput &= StderrRead($iPID) If @error Then ; Exit the loop if the process closes or StderrRead returns an error. ExitLoop EndIf WEnd ConsoleWrite('>' & $sOutput & '<' & @CRLF) EndFunc ;==>Example anyone knows how to get the info this exe gives ? Thanks Edited December 1, 2018 by argumentum SOLVED Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
TheDcoder Posted December 1, 2018 Posted December 1, 2018 If you are able to do it from command prompt, did you check the location using the where command? Also try calling the executable directly instead of doing it via ComSpec. EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
argumentum Posted December 1, 2018 Author Posted December 1, 2018 Tried it all @TheDcoder, it does not work. Try it in your PC. Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted December 1, 2018 Author Posted December 1, 2018 (edited) #AutoIt3Wrapper_UseX64=y ..that's it. =) ..or.. #include <WinAPIFiles.au3> _WinAPI_Wow64EnableWow64FsRedirection ( $bEnable ) if you wanna run 32bit anyway. Final code: expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_UseX64=n #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <Array.au3> Local $a = Example() Func Example() ; how to run the x64 when not compiled as x64 Local $t = TimerInit() If StringInStr(@OSArch, "64") Then _WinAPI_Wow64EnableWow64FsRedirection(False) Local $iPID = Run(@ComSpec & ' /c "' & @WindowsDir & '\System32\qwinsta.exe"', @WindowsDir & '\System32', @SW_HIDE, BitOR($STDERR_CHILD, $STDOUT_CHILD)) Local $aOutput, $sOutput = "" While 1 $sOutput &= StdoutRead($iPID) If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf WEnd While 1 $sOutput &= StderrRead($iPID) If @error Then ; Exit the loop if the process closes or StderrRead returns an error. ExitLoop EndIf WEnd If StringInStr(@OSArch, "64") Then _WinAPI_Wow64EnableWow64FsRedirection(True) ; needs to be re-enabled ASAP If Not StringInStr($sOutput, "SESSIONNAME") Then Return SetError(1, 0, "") Local $a, $n, $b, $m, $i = -1 $b = StringSplit($sOutput, @CRLF, 1) Dim $a[UBound($b) + 1][7] For $n = 1 To UBound($b) - 1 If $b[$n] = "" Then ContinueLoop $i += 1 $a[$i][0] = StringMid($b[$n], 1, 1) ; Current $a[$i][1] = StringMid($b[$n], 2, 18) ; SESSIONNAME $a[$i][2] = StringMid($b[$n], 20, 42 - 20) ; USERNAME $a[$i][3] = StringMid($b[$n], 42, 49 - 42) ; ID $a[$i][4] = StringMid($b[$n], 49, 57 - 49) ; STATE $a[$i][5] = StringMid($b[$n], 57, 69 - 57) ; TYPE $a[$i][6] = StringMid($b[$n], 69) ; DEVICE Next ReDim $a[$i + 1][7] For $m = 0 To UBound($a, 2) - 1 For $n = 0 To UBound($a) - 1 If $m = 3 And $n Then $a[$n][$m] = Int($a[$n][$m]) Else $a[$n][$m] = StringStripWS($a[$n][$m], 3) EndIf Next Next $a[0][0] = $i _ArrayDisplay($a, "TimerDiff: " & TimerDiff($t)) Return $a EndFunc ;==>Example may help the next copy'n'paster ( like me ) PS: uploaded to the downloads the utility that gets this array and runs MsTsc to shadow a user. Edited December 1, 2018 by argumentum post the solution Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
argumentum Posted March 15, 2019 Author Posted March 15, 2019 Update: No need to use qwinsta anymore. I now use DLL calls. Code at https://www.autoitscript.com/forum/topic/198186-listusersessions/ Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now