Simmy Posted June 7, 2011 Share Posted June 7, 2011 Hi Everyone, Thanks so much for the opportunity to post. This is my first one. Guys, Im a newbie to autoit, and trying to work out what is wrong with the code im working on. Basically, here is what im trying to do is to use dsquery computer -name <computername> * to return all computers from Active Directory. The problem is that even though I get multiple records returned in the outputted text file, only one line is being displayed in my Edit Control, and that line is the very last line from that text file. Any help would be greatly appreciated. expandcollapse popup#include <Constants.au3> #include <GUIConstants.au3> #include <ListboxConstants.au3> #include <EditConstants.au3> #include <ListviewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> $pcname = InputBox("PC Name","Please input a Computer Name:") RunWait(@ComSpec & ' /c dsquery.exe computer -name ' & $pcname & '* > c:\pcname.txt','',@SW_HIDE) GUICreate("PC Name", 700,300) GUICtrlCreateLabel ($pcname, 10, 10) $mylist=GUICtrlCreateEdit("", 10,30,500,200, $WS_VSCROLL) $close=GUICtrlCreateButton ("Close", 75,370,55,25) $FileOpen = FileOpen('c:\pcname.txt', 0) If $FileOpen = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf While 1 $line = FileReadLine($FileOpen) If $line = "" Then ExitLoop GUICtrlSetData($mylist,$line) Wend FileClose($FileOpen) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $close FileDelete('c:\pcname.txt') Exit EndSelect Wend Link to comment Share on other sites More sharing options...
UEZ Posted June 7, 2011 Share Posted June 7, 2011 Try _GUICtrlEdit_AppendText($mylist, $line & @CRLF) instead of GUICtrlSetData($mylist,$line).You have to include GuiEdit.au3.Br,UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
ahmet Posted June 7, 2011 Share Posted June 7, 2011 Or you can do like this$read=FileRead($FileOpen) GUICtrlSetData($mylist,$read) Link to comment Share on other sites More sharing options...
Simmy Posted June 7, 2011 Author Share Posted June 7, 2011 Hi UEZ and ahmet. Guys thanks so much for this I really appreciate it. Can I please just ask 2 more things about this code? What you guys have given to me works, so I really thank you for that. Issue 1: Currently, if I enter nothing, and click on either cancel or ok button, I still get results back. What I would like is: If the Cancel button is selected, then the script exits. If nothing is put into the input box, and the ok button is clicked, then a msgbox would come up prompting you to "You must first enter a computer". Issue 2: When the results are returned, its as if the original controls have vanished. That is, I cannot see the label control for: GUICtrlCreateLabel etc. Is there a way to have the input box visible all the time along with the label, so that when the results are returned in the edit control, I can see the label, input box, and edit control? I so much appreciate your kind help. Link to comment Share on other sites More sharing options...
UEZ Posted June 7, 2011 Share Posted June 7, 2011 (edited) 1) Try this: #include <Constants.au3> #include <GUIConstants.au3> #include <ListboxConstants.au3> #include <EditConstants.au3> #include <ListviewConstants.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Do $pcname = InputBox("PC Name","Please input a Computer Name:") If @error = 1 Then Exit MsgBox(0, "Information", "Closing script") If $pcname = "" Then MsgBox(0, "Information", "You must enter a computer name") Until $pcname <> "" RunWait(@ComSpec & ' /c dsquery.exe computer -name ' & $pcname & '* > c:\pcname.txt','',@SW_HIDE) GUICreate("PC Name", 700,300) GUICtrlCreateLabel ($pcname, 10, 10) $mylist=GUICtrlCreateEdit("", 10,30,500,200, $WS_VSCROLL) $close=GUICtrlCreateButton ("Close", 600,70,55,25) $read=FileRead("c:\pcname.txt") GUICtrlSetData($mylist,$read) GUISetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $close FileDelete('c:\pcname.txt') Exit EndSelect Wend 2) I can see the label with the name you entered in the input box. The close button is behind the edit control. The input box cannot be visible with the main gui because input box will stop the script until you entered something. Br, UEZ Edited June 7, 2011 by UEZ Please don't send me any personal message and ask for support! I will not reply! Selection of finest graphical examples at Codepen.io The own fart smells best! ✌Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!¯\_(ツ)_/¯ ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ Link to comment Share on other sites More sharing options...
Simmy Posted June 8, 2011 Author Share Posted June 8, 2011 Thanks so much UEZ you are a champion. 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