Function for CMD:
;~ #RequireAdmin
#include <File.au3>
If @OSArch = "X64" And Not @AutoItX64 Then _Wow64FsRedirection(0)
Local $output= _RunCmd_GetOutput("qwinsta")
;~ Local $output=_StreamCMD("ping 8.8.8.8")
Local $username=StringStripWS(StringMid($output,StringinStr($output,"console")+18,20),3)
MsgBox(0, "", $username)
Func _RunCmd_GetOutput($sCommand)
ConsoleWrite("+Execute: " & $sCommand & @CRLF)
Local $sOutput = '', $iPID = Run('"' & @ComSpec & '" /c ' & $sCommand, '', @SW_HIDE, 0x6)
Do
$sOutput &= StdoutRead($iPID)
Until @error
Do
$sOutput &= StderrRead($iPID)
Until @error
ConsoleWrite($sOutput&@CRLF)
Return $sOutput
EndFunc ;==>_RunCmd
Func _StreamCMD($sCMD, $sCallBackFunction = Default, $WorkingDir = Default, $iStreamType = Default, $iShowFlag = Default, $iDelay = Default)
If StringStripWS($sCMD, 8) = "" Then Return ""
If $sCallBackFunction = Default Then $sCallBackFunction = "ConsoleWrite"
;~ If $WorkingDir = Default Then $WorkingDir = @SystemDir ;@WindowsDir & '\System32'
If $WorkingDir = Default Then $WorkingDir = @WindowsDir & '\System32'
If $iStreamType = Default Then $iStreamType = $STDERR_CHILD + $STDOUT_CHILD
If $iShowFlag = Default Then $iShowFlag = False
If $iDelay = Default Then $iDelay = 250
ConsoleWrite("! Execute: " & $sCMD & @CRLF)
Local $sTMP = '', $sSTD = '', $sCOM = '"' & @WindowsDir & '\System32\cmd.exe"' & ' /c ' & $sCMD
;~ Local $sTMP = '', $sSTD = '', $sCOM = @ComSpec & ' /c ' & $sCMD
Local $iWin = $iShowFlag ? @SW_SHOW : @SW_HIDE
Local $iPID = Run($sCOM, $WorkingDir, $iWin, $iStreamType)
While 1
$sTMP = StdoutRead($iPID, False, False)
If @error Then ExitLoop
If $sTMP <> "" Then
$sTMP = StringReplace($sTMP, @CR & @CR, '')
$sSTD &= $sTMP
Call($sCallBackFunction,$sTMP)
;~ ConsoleWrite($sTMP)
Sleep($iDelay)
EndIf
WEnd
While 1
$sTMP = StderrRead($iPID, False, False)
If @error Then ExitLoop
If $sTMP <> "" Then
$sTMP = StringReplace($sTMP, @CR & @CR, '')
$sSTD &= $sTMP
Call($sCallBackFunction,$sTMP)
;~ ConsoleWrite($sTMP)
Sleep($iDelay)
EndIf
WEnd
;~ If $sSTD <> "" Then ConsoleWrite(@CRLF)
Return SetError(@error, @extended, $sSTD)
EndFunc ;==>_StreamCMD
; * -----:| Dao Van Trong - TRONG.WIN
Func _Wow64FsRedirection($state)
If @OSArch = "X64" Then
If $state Then
;DllCall("kernel32.dll", "int", "Wow64EnableWow64FsRedirection", "int", 1)
DllCall("kernel32.dll", "int", "Wow64RevertWow64FsRedirection", "int", 0)
Else
;DllCall('kernel32.dll', 'boolean', 'Wow64EnableWow64FsRedirection', 'boolean', False)
DllCall("kernel32.dll", "int", "Wow64DisableWow64FsRedirection", "int", 0)
EndIf
If @error Then Return SetError(1, 0, 0)
Return 1
EndIf
EndFunc ;==>_Wow64FsRedirection