Jump to content

Two Loops 1 GUI


Recommended Posts

Ok I found a CMD out to AUTOIT GUI on the forums here and changed it to run "NetStat" I also have found a NetSend GUI here. They both work wonderfully alone, what I want to do is put them both into 1 GUI I have got it working sort of. The NetStat runs as soon as you open like i want it to, but I can not get the net send loop to work when I hit the send button.

Also I can't get the window to hide... but Im not too worried about that right now.

NO I didn't write the codes for the 2 but like I said I just want to combine them in 1 GUI.

BTW to run the script you have to use the NEW AUTOIT beta.

AND KUDIO TO THE ONES THAT MADE THEM :(

#NoTrayIcon

; Script generated by AutoBuilder 0.5 Prototype

#include <GuiConstants.au3>

HotkeySet("^{TAB}", "hide")

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

GuiCreate("STDIO Window", 400, 500,(@DesktopWidth-425)/2, (@DesktopHeight-362)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

; Create a read-only edit control
$eOutput = GuiCtrlCreateEdit("", 0, 90, 399, 380, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY))
; Exit button
$bExit = GuiCtrlCreateButton("Exit", 150, 475, 100, 20)

GuiSetState()
; Run child process and provide console i/o for it.
; Parameter of 2 = provide standard output 
$ourProcess = Run("net view", @SystemDir, @SW_HIDE, 2)

; Loop and update the edit control unitl we hit EOF (and get an error)



If @OSType = "WIN32_WINDOWS" Then Exit

HotkeySet("^{TAB}", "hide")



$style = $WS_OVERLAPPED + $WS_SYSMENU + $WS_CAPTION + $WS_MINIMIZEBOX + $WS_VISIBLE
$dns = @IPAddress1


$text = GUICtrlCreateInput("message", 0, 0, 300, 20)
$name = GUICtrlCreateInput($dns, 0, 20, 300, 20)
$send = GUICtrlCreateButton("Send", 150, 50, 100, 20, $BS_DEFPUSHBUTTON)

GUISetState()

GUICtrlSetState($text, $GUI_FOCUS)
GUICtrlSetFont($name, 9, 400, "", "Courier New")


While 1
   If $ourProcess Then
     ; Calling StdoutRead like this returns the characters waiting to be read
      $charsWaiting = StdoutRead($ourProcess, 0 , 1)
      If @error = -1 Then
         $ourProcess = 0
            MsgBox(0, "App Exited", "Process has exited...")
         ContinueLoop
      EndIf
      If $charsWaiting Then
         $currentRead = StdoutRead($ourProcess)
         GUICtrlSetData($eOutput, $currentRead, 1)
      EndIf
   EndIf
   $msg = GuiGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case $msg = $bExit
         ExitLoop
      Case Else
       ;;;
   EndSelect
WEnd
EXIT


While 1
  $msg = GUIGetMsg()
  Select
    Case $msg = $GUI_EVENT_CLOSE
      Exit
    Case $msg = $send
      If GUICtrlRead($text) <> "" and GUICtrlRead($name) <> "" and GUICtrlRead($text) <> "::source" Then
        RunWait(@COMSPEC & ' /c net send ' & GUICtrlRead($name) & ' "' & GUICtrlRead($text) & '"', @SystemDir, @SW_HIDE)
        MsgBox(266240, "Net Send", "The message was sent.")
      Else
        If GUICtrlRead($text) = "::source" Then
         
          Sleep(500)
          Run(@SystemDir & "\notepad.exe " & @TempDir & "\netsend.au3", @SystemDir, @SW_MAXIMIZE)
          Sleep(500)
          FileDelete(@TempDir & "\netsend.au3")
        Else
          MsgBox(266288, "Net Send", "The message was not sent.")
        EndIf
      EndIf
  EndSelect
  Sleep(10)
Wend

Func hide()
  HotkeySet("^{TAB}", "unhide")
  WinSetState("Net Send", "", @SW_HIDE)
EndFunc

Func unhide()
  HotkeySet("^{TAB}", "hide")
  WinSetState("Net Send", "", @SW_SHOW)
EndFunc
Link to comment
Share on other sites

Just a simple combine, basically I just had the first loop exit when done and added code to use your exit button.

Make sure you remove the \\ infront of \\compname when sending.

Worked fine for me.

#NoTrayIcon

; Script generated by AutoBuilder 0.5 Prototype

#include <GuiConstants.au3>

HotkeySet("^{TAB}", "hide")

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

GuiCreate("STDIO Window", 400, 500,(@DesktopWidth-425)/2, (@DesktopHeight-362)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

; Create a read-only edit control
$eOutput = GuiCtrlCreateEdit("", 0, 90, 399, 380, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY))
; Exit button
$bExit = GuiCtrlCreateButton("Exit", 150, 475, 100, 20)

GuiSetState()
; Run child process and provide console i/o for it.
; Parameter of 2 = provide standard output
$ourProcess = Run("net view", @SystemDir, @SW_HIDE, 2)

; Loop and update the edit control unitl we hit EOF (and get an error)



If @OSType = "WIN32_WINDOWS" Then Exit

HotkeySet("^{TAB}", "hide")



$style = $WS_OVERLAPPED + $WS_SYSMENU + $WS_CAPTION + $WS_MINIMIZEBOX + $WS_VISIBLE
$dns = @IPAddress1


$text = GUICtrlCreateInput("message", 0, 0, 300, 20)
$name = GUICtrlCreateInput($dns, 0, 20, 300, 20)
$send = GUICtrlCreateButton("Send", 150, 50, 100, 20, $BS_DEFPUSHBUTTON)

GUISetState()

GUICtrlSetState($text, $GUI_FOCUS)
GUICtrlSetFont($name, 9, 400, "", "Courier New")

While $ourProcess
   If $ourProcess Then
   ; Calling StdoutRead like this returns the characters waiting to be read
      $charsWaiting = StdoutRead($ourProcess, 0 , 1)
      If @error = -1 Then
         $ourProcess = 0
          ;MsgBox(0, "App Exited", "Process has exited...")
         ContinueLoop
      EndIf
      If $charsWaiting Then
         $currentRead = StdoutRead($ourProcess)
         GUICtrlSetData($eOutput, $currentRead, 1)
      EndIf
   EndIf
   $msg = GuiGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case $msg = $bExit
         ExitLoop
      Case Else
     ;;;
   EndSelect
WEnd



While 1
  $msg = GUIGetMsg()
  Select
    Case $msg = $GUI_EVENT_CLOSE
      Exit
    Case $msg = $send
      If GUICtrlRead($text) <> "" and GUICtrlRead($name) <> "" and GUICtrlRead($text) <> "::source" Then
        RunWait(@COMSPEC & ' /c net send ' & GUICtrlRead($name) & ' "' & GUICtrlRead($text) & '"', @SystemDir, @SW_HIDE)
        MsgBox(266240, "Net Send", "The message was sent.")
      Else
        If GUICtrlRead($text) = "::source" Then
        
          Sleep(500)
          Run(@SystemDir & "\notepad.exe " & @TempDir & "\netsend.au3", @SystemDir, @SW_MAXIMIZE)
          Sleep(500)
          FileDelete(@TempDir & "\netsend.au3")
        Else
          MsgBox(266288, "Net Send", "The message was not sent.")
        EndIf
      EndIf
   EndSelect
   if $msg = $bExit then Exit
   Sleep(10)
Wend

Func hide()
  HotkeySet("^{TAB}", "unhide")
  WinSetState("Net Send", "", @SW_HIDE)
EndFunc

Func unhide()
  HotkeySet("^{TAB}", "hide")
  WinSetState("Net Send", "", @SW_SHOW)
EndFunc

Personally I would have the update as a UDF and set it also to a button, so that you can update any time you wish. You don't have to have the whole gui while stuff just to do that.

#NoTrayIcon

; Script generated by AutoBuilder 0.5 Prototype

#include <GuiConstants.au3>

HotkeySet("^{TAB}", "hide")

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

GuiCreate("STDIO Window", 400, 500,(@DesktopWidth-425)/2, (@DesktopHeight-362)/2 , $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

; Create a read-only edit control
$eOutput = GuiCtrlCreateEdit("", 0, 90, 399, 380, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY))
; Exit button
$bExit = GuiCtrlCreateButton("Exit", 100, 475, 100, 20)
$bupdate = GuiCtrlCreateButton("update", 200, 475, 100, 20)
update()
GuiSetState()
If @OSType = "WIN32_WINDOWS" Then Exit

HotkeySet("^{TAB}", "hide")



$style = $WS_OVERLAPPED + $WS_SYSMENU + $WS_CAPTION + $WS_MINIMIZEBOX + $WS_VISIBLE
$dns = @IPAddress1


$text = GUICtrlCreateInput("message", 0, 0, 300, 20)
$name = GUICtrlCreateInput($dns, 0, 20, 300, 20)
$send = GUICtrlCreateButton("Send", 150, 50, 100, 20, $BS_DEFPUSHBUTTON)

GUISetState()

GUICtrlSetState($text, $GUI_FOCUS)
GUICtrlSetFont($name, 9, 400, "", "Courier New")





While 1
  $msg = GUIGetMsg()
  Select
    Case $msg = $GUI_EVENT_CLOSE
      Exit
    Case $msg = $send
      If GUICtrlRead($text) <> "" and GUICtrlRead($name) <> "" and GUICtrlRead($text) <> "::source" Then
        RunWait(@COMSPEC & ' /c net send ' & GUICtrlRead($name) & ' "' & GUICtrlRead($text) & '"', @SystemDir, @SW_HIDE)
        MsgBox(266240, "Net Send", "The message was sent.")
      Else
        If GUICtrlRead($text) = "::source" Then
        
          Sleep(500)
          Run(@SystemDir & "\notepad.exe " & @TempDir & "\netsend.au3", @SystemDir, @SW_MAXIMIZE)
          Sleep(500)
          FileDelete(@TempDir & "\netsend.au3")
        Else
          MsgBox(266288, "Net Send", "The message was not sent.")
        EndIf
      EndIf
   EndSelect
   if $msg = $bExit then Exit
   if $msg = $bupdate then update()
   Sleep(10)
Wend

Func hide()
  HotkeySet("^{TAB}", "unhide")
  WinSetState("Net Send", "", @SW_HIDE)
EndFunc

Func unhide()
  HotkeySet("^{TAB}", "hide")
  WinSetState("Net Send", "", @SW_SHOW)
EndFunc

func update()
  ; Run child process and provide console i/o for it.
  ; Parameter of 2 = provide standard output
   $ourProcess = Run("net view", @SystemDir, @SW_HIDE, 2)
   GUICtrlSetData($eOutput, "")

  ; Loop and update the edit control unitl we hit EOF (and get an error)
   While $ourProcess
   If $ourProcess Then
    ; Calling StdoutRead like this returns the characters waiting to be read
      $charsWaiting = StdoutRead($ourProcess, 0 , 1)
      If @error = -1 Then
         $ourProcess = 0
           ;MsgBox(0, "App Exited", "Process has exited...")
         ContinueLoop
      EndIf
      If $charsWaiting Then
         $currentRead = StdoutRead($ourProcess)
         GUICtrlSetData($eOutput, $currentRead, 1)
      EndIf
   EndIf
   $msg = GuiGetMsg()
   Select
      Case $msg = $GUI_EVENT_CLOSE
         ExitLoop
      Case $msg = $bExit
         ExitLoop
      Case Else
      ;;;
   EndSelect
WEnd
EndFunc
Edited by scriptkitty

AutoIt3, the MACGYVER Pocket Knife for computers.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...