DavidLago Posted April 18, 2011 Share Posted April 18, 2011 Hello, people. Yeah, I give up. I have been striving not to fall for the forum help and leave you guys out of my troubles, but since I'm a beginner, some point I'd get stuck on something, and now I am. The thing is, I'm trying to build a script to check connections on my domain to the servers using the dos command "qwinsta". With it's sintax: qwinsta /server:ServerName And it will be displayed like this: C:\Windows\system32>qwinsta /server:NameOfTheServer SESSIONNAME USERNAME ID STATE TYPE console adm-user1 0 Active wdcon rdp-tcp 65536 Listen rdpwd adm-user2 1 Disc rdpwd I suppose that if I need to work woth those informations with autoit, I need to export these data to a file in temp dir or whatever. Well, if it Type that below, it works perfectly: C:\Windows\system32>qwinsta /server:NameOfTheServer > c:\test\logwinsta.log But if I run the @ComSpec in autoit and run that command, it doesn't work! I tried a lot of different combinations and NADA. So, here is my script so far: ; Script Start $UserName = InputBox("..::Antentication::..", "Administrator User: ", "adm-" & @UserName, "", "110", "130") $PassWD = InputBox("..::Antentication::..", "Password: ", "", "¤", "110", "130") $Server = InputBox("Servidor: ", "Servidor: ", "Server00", "", "110", "130") ; If @error = 1 Then Exit $Qwinsta = "qwinsta /server:" & $Server & "" $Rwinsta = "qwinsta /server:" & $Server & "" $Command = @ComSpec & " /c " & $Qwinsta $Export = " > c:\Scripts\logwinsta.txt" Local $pid = RunAs($UserName, "MyDomain", $PassWD, 4, @ComSpec, @SystemDir, $Command & $Export) Exit You can try several ways to put that to work, and it just doesn't! Any help? Link to comment Share on other sites More sharing options...
hannes08 Posted April 18, 2011 Share Posted April 18, 2011 Hi HellFrost, did you try using StdoutRead() so you don't have to pipe the text to a file and then read it? Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted April 18, 2011 Share Posted April 18, 2011 Hi and Welcome to the forums! Can't you use StdoutRead()? See helpfile for details and example. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
DavidLago Posted April 19, 2011 Author Share Posted April 19, 2011 Thanks people! I wasn't aware about this feature's existance! I'm gonna try to squeeze the resources of this thingy and will post the results afterwards Link to comment Share on other sites More sharing options...
flyingboz Posted April 23, 2011 Share Posted April 23, 2011 dos command "qwinsta". I suppose that if I need to work woth those informations with autoit, I need to export these data to a file in temp dir or whatever._RunReadStd() is your friend. Reading the help file before you post... Not only will it make you look smarter, it will make you smarter. Link to comment Share on other sites More sharing options...
DavidLago Posted April 24, 2011 Author Share Posted April 24, 2011 _RunReadStd() is your friend.I guess he is, Flyboz,Gonna post my script here soon, still having some issues on executing an application inside my domain... Link to comment Share on other sites More sharing options...
DavidLago Posted April 28, 2011 Author Share Posted April 28, 2011 Hi and Welcome to the forums! Can't you use StdoutRead()? See helpfile for details and example. People, Why it ALWAYS returns me two Dialog boxes? I mean, let me show you: OBS: You'll need to edit some of the lines, once you're probably out of a domain or are in a different one. #include <Constants.au3> Global $UserName = "adm-" & @UserName Global $PassWD = InputBox("..::Autenticação::..", "Digite a senha para: " & @CRLF & @CRLF & " ADM-" & @UserName, "", "¤", "240", "164") Local $foo = RunAs($UserName, "DOMAIN", $PassWD, 4, @ComSpec & " /c ipconfig", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $line While 1 $line = StdoutRead($foo) If @error Then ExitLoop If $line <> "" Then MsgBox(0, "STDOUT read:", $line) EndIf WEnd Exit Notice that it gives me TWO dialog boxes, no matter what I do. ____________ After that, I want some other advice too. Can I use this function to import data to a "ListView"? Separated by columns and all? (Just trying to predict the next steps) Link to comment Share on other sites More sharing options...
hannes08 Posted April 28, 2011 Share Posted April 28, 2011 (edited) Hi HellFrost, well your output has more than one line, right? So you could, just for an example do sth like: Local $foo = RunAs($UserName, "DOMAIN", $PassWD, 4, @ComSpec & " /c ipconfig", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $line While 1 $line = StdoutRead($foo) If @error Then ExitLoop If $line <> "" Then $line &= $line EndIf WEnd MsgBox(0,"STDout read:", $line) After that you could split the string $line on the linebreak ( StringSplit($line, @CRLF) ) and import the array elements into a ListView. Edit: By the way, it's not a good idea to call your variables 'foo' or 'bar', even if the example says so. This should be for testing reasons only. Edited April 28, 2011 by Hannes123 Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
DavidLago Posted April 28, 2011 Author Share Posted April 28, 2011 I worked a way around the problem... Adding : While 1 Sleep(3000) $line = StdoutRead($foo) If $line <> "" Then MsgBox(0, "STDOUT read:", $line) _______ Not sure this is the best way to work this out, huh? Link to comment Share on other sites More sharing options...
4Eyes Posted April 29, 2011 Share Posted April 29, 2011 It seems that this is a Windows 7 issue as it won't work right now on my notebook but I'm quite certain it works under XP. Oh well, it gives me something else to do while Mrs 4Eyes hogs the big TV watching 'the wedding'. Sigh. 4Eyes Link to comment Share on other sites More sharing options...
DavidLago Posted April 29, 2011 Author Share Posted April 29, 2011 Hi HellFrost, well your output has more than one line, right? So you could, just for an example do sth like: Local $foo = RunAs($UserName, "DOMAIN", $PassWD, 4, @ComSpec & " /c ipconfig", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $line While 1 $line = StdoutRead($foo) If @error Then ExitLoop If $line <> "" Then $line &= $line EndIf WEnd MsgBox(0,"STDout read:", $line) After that you could split the string $line on the linebreak ( StringSplit($line, @CRLF) ) and import the array elements into a ListView. Edit: By the way, it's not a good idea to call your variables 'foo' or 'bar', even if the example says so. This should be for testing reasons only. Oh, hey again! and yeah, I always change the names, they're actually changed, I just post them here with different variables names to make it easier for you to help me, thanks for the advice though. Now that I use the funcion Stdoutread, I managed to display what I want to be displayed in a dialogbox, and even exported a log for testing purposes. What I want now is to import them into a listview inside a Guiwindow. When exported, the log comes out like this: (as well as the stdoutread when displayed in a dialogbox) SESSIONNAME USERNAME ID STATE TYPE DEVICE console adm-ricardoac 0 Active wdcon rdp-tcp 65536 Listen rdpwd adm-ademarz 2 Disc rdpwd I want to have them enter automatically. I'm gonna try to reproduce my environment below for you to understand: (I'm sorry I can't polish enough to make it smaller, this is only one screen which can be called from the main Screen). expandcollapse popup#include <Constants.au3> #include <StaticConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ListBoxConstants.au3> #include <GuiButton.au3> #include <Array.au3> #include <Constants.au3> Global $UserName = "adm-" & @UserName Global $PassWD = InputBox("..::Autenticação::..", "Digite a senha para: " & @CRLF & @CRLF & " ADM-" & @UserName, "", "¤", "240", "164") Global $config = "config" INTERFACEWINSTA() Func INTERFACEWINSTA() Opt('MustDeclareVars', 1) Local $btnQwinsta Local $btnRwinsta Local $btnDerrubar Local $btnExit Local $btnKEY2 Local $ServerInput = "BRJGS" Local $listview, $item1, $item2, $item3, $item4, $msgList GUICreate(". . : : Windows Station Manager : : . .", 400, 300, @DesktopWidth / 2 - 160, @DesktopHeight / 2 - 45, -1, 0x00000018); WS_EX_ACCEPTFILES) GUICtrlCreateLabel("Server: ", 10, 13, 40) Global $nameServer = GUICtrlCreateInput($ServerInput, 50, 11, 70, 20) GUICtrlSetState(-1, $GUI_DROPACCEPTED) GUISetBkColor(0x00E0FFFF) ; will change background color $listview = GUICtrlCreateListView("TIPO SESSÃO |USUÁRIO |ID |PROTOCOLO ", 10, 44, 385, 220);,$LVS_SORTDESCENDING) GUISetHelp("cmd") ; Roda bloco de notas com F1 $btnQwinsta = GUICtrlCreateButton("Query Windows Station", 130, 8, 130) $btnRwinsta = GUICtrlCreateButton("Reset Windows Station", 265, 8, 130) $btnExit = GUICtrlCreateButton("Exit", 325, 270, 70) ;GUICtrlCreateLabel(".: M-Windows Station :.", 12, 8, 210) ;GUICtrlCreateLabel("Server: " & $Server, 140, 8, 210) GUISetState() While 1 Global $QWScommand = "/c qwinsta /server:" Global $RWScommand = "/c rwinsta /server:" Global $nameServerStr = GUICtrlRead($nameServer) $btnKEY2 = GUIGetMsg() Select Case $btnKEY2 = $GUI_EVENT_CLOSE Exit Case $btnKEY2 = $btnQwinsta ;MsgBox(0, "", $nameServerStr) ;Local $Proc = RunAs($UserName, "Domain", $PassWD, 4, @ComSpec & $QWScommand & $nameServerStr, @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $Proc = RunAs($UserName, "Domain", $PassWD, 4, @ComSpec & " /c qwinsta /server:"&$nameServerStr, @ScriptDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 Sleep(1000) Local $WinStaResult = StdoutRead($Proc) If $WinStaResult <> "" Then MsgBox(0, "STDOUT read:", $WinStaResult) ;~ If FileExists(@ScriptDir & "\" & "teste.log") Then ;~ FileDelete(@ScriptDir & "\" & "teste.log") ;~ EndIf FileWriteLine(@ScriptDir & "\" & "teste.log", $WinStaResult) EndIf ExitLoop WEnd Case $btnKEY2 = $btnRwinsta MsgBox(0, "", "Rwinsta " & $nameServerStr) Case $btnKEY2 = $btnExit Exit EndSelect WEnd EndFunc ;==>INTERFACEWINSTA So, I got no idea how to do that. Actually I got one: Maybe trying to stringsplit them into arrays and defining each splitted array to a variable and throwing them into listviewitem? Maybe you guys could give me an example if this thought is right? Thanks a million! --- HellFrost Link to comment Share on other sites More sharing options...
hannes08 Posted April 29, 2011 Share Posted April 29, 2011 Hi HellFrost, see this small example: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $txt = "SESSIONNAME USERNAME ID STATE TYPE DEVICE " & @CRLF & "console adm-ricardoac 0 Active wdcon " & @CRLF & "rdp-tcp 65536 Listen rdpwd " & @CRLF & "adm-ademarz 2 Disc rdpwd " $a_temp = StringSplit($txt, @CRLF) $hGUI = GUICreate("Form1", 420, 220, -1, -1) $listview = GUICtrlCreateListView(StringReplace($a_temp[1]," ", "|"),10,10, 400, 200) For $i = 2 To $a_temp[0] $a_temp[$i] = GUICtrlCreateListViewItem(StringReplace($a_temp[$i]," ", "|"), $istview) Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ... no errorchecking has been done here ... Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler] Link to comment Share on other sites More sharing options...
DavidLago Posted April 29, 2011 Author Share Posted April 29, 2011 Hi HellFrost, see this small example: #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $txt = "SESSIONNAME USERNAME ID STATE TYPE DEVICE " & @CRLF & "console adm-ricardoac 0 Active wdcon " & @CRLF & "rdp-tcp 65536 Listen rdpwd " & @CRLF & "adm-ademarz 2 Disc rdpwd " $a_temp = StringSplit($txt, @CRLF) $hGUI = GUICreate("Form1", 420, 220, -1, -1) $listview = GUICtrlCreateListView(StringReplace($a_temp[1]," ", "|"),10,10, 400, 200) For $i = 2 To $a_temp[0] $a_temp[$i] = GUICtrlCreateListViewItem(StringReplace($a_temp[$i]," ", "|"), $istview) Next GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd ... no errorchecking has been done here ... Thanks a lot, man! I'm going to study that example and work over it now! You're going to heaven! Link to comment Share on other sites More sharing options...
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