Jump to content

Recommended Posts

Posted (edited)

I haven't worked with GUI's much at all and it probably shows. The general idea is to have 2 input boxes and an OK and Cancel button in a simple GUI. What I want to happen is the information input in var $s_Machine and var $s_Process to embed into $runString when I click the $okbutton. Any tips are appreciated.

Opt("GUIOnEventMode", 1)
#Include <GuiConstants.au3>
#Include <Constants.au3>

$mainwindow = GUICreate("Remote End Process", 225, 150)
GUICtrlCreateLabel("Enter Computer Name", 37.5, 15)
GUICtrlCreateLabel("Process to End", 37.5, 60)
$okbutton = GUICtrlCreateButton("OK", 41.25, 110, 60)
$cancelbutton = GUICtrlCreateButton("Cancel", 123.75, 110, 60)
$s_Machine = GuiCtrlCreateInput("Machine Name", 37.5, 30, 150, 20)
$s_Process = GuiCtrlCreateInput("Process", 37.5, 75, 150, 20)
;$runString = StringFormat("taskkill /s %s /u administrator /p adminpass /im %s", $s_Machine, $s_Process)
;$run = Run($runString, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
;GUICtrlSetState( -1, $GUI_DEFBUTTON)
GUICtrlSetOnEvent($okbutton, "OKButton")
GUICtrlSetOnEvent($cancelbutton, "CancelButton")
GUISetOnEvent($GUI_EVENT_CLOSE, "XButton")
GUISetState(@SW_SHOW)

While 1
  Sleep(1000)
WEnd

Func OKButton()
    
$runString = StringFormat("taskkill /s %s /u administrator /p adminpass /im %s", $s_Machine, $s_Process)
$run = Run($runString, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StdoutRead($run)
    If @error Then ExitLoop
    MsgBox(0, "Success:", $line)
Wend

While 1
    $line = StderrRead($run)
    If @error Then ExitLoop
    MsgBox(0, "Error:", $line)
WEnd
EndFunc


Func CancelButton()
  ;MsgBox(1, "Closing Script", "No commands were sent!")
  Exit
EndFunc


Func Xbutton()
  Exit
EndFunc

Edit: Updated topic name.

Edited by schilbiz
Posted

Currently your $s_Machine and $s_Process hold the control id.

You have to query the value with GuiCtrlRead() in your OKButton func.

$real_s_Machine = GuiCtrlRead($s_Machine)oÝ÷ Ûú®¢×z¼ ¢m©äÊ·ÜuçmëÚX§zËh¶(­¶ÚØ­0¢¹,){^×jëh×6$real_s_Machine = GuiCtrlRead($s_Machine)
$real_s_Process = GuiCtrlRead($s_Process)
Posted

If I wanted to add some exclusions to what could be typed into inputbox $s_Machine = GuiCtrlCreateInput("", 37.5, 30, 150, 20) how would I go about that?

Also how can I make it so you can just hit the "Enter" key and it will trigger the Func OKButton()? I have been trying to use GUICtrlSetState( -1, $GUI_DEFBUTTON) but am not able to get it to work.

Thanks guys,

It just dawned on me ... Should this be in the GUI Support Forum?

Opt("GUIOnEventMode", 1)
#Include <GuiConstants.au3>
#Include <Constants.au3>

$mainwindow = GUICreate("Remote End Process", 225, 150)
GUICtrlCreateLabel("Enter Computer Name", 37.5, 15)
GUICtrlCreateLabel("Process to End", 37.5, 60)
$okbutton = GUICtrlCreateButton("OK", 41.25, 110, 60)
$cancelbutton = GUICtrlCreateButton("Cancel", 123.75, 110, 60)
$s_Machine = GuiCtrlCreateInput("Machine Name", 37.5, 30, 150, 20)
$s_Process = GuiCtrlCreateInput("Process", 37.5, 75, 150, 20)
GUICtrlSetOnEvent($okbutton, "OKButton")
GUICtrlSetOnEvent($cancelbutton, "CancelButton")
GUISetOnEvent($GUI_EVENT_CLOSE, "XButton")
GUISetState(@SW_SHOW)

While 1
  Sleep(1000)
WEnd

Func OKButton()
    
$real_s_Machine = GuiCtrlRead($s_Machine)
$real_s_Process = GuiCtrlRead($s_Process)
$runString = StringFormat("taskkill /s %s /u administrator /p adminpass /im %s", $real_s_Machine, $real_s_Process)
$run = Run($runString, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StdoutRead($run)
    If @error Then ExitLoop
    MsgBox(0, "Success:", $line)
Wend

While 1
    $line = StderrRead($run)
    If @error Then ExitLoop
    MsgBox(0, "Error:", $line)
WEnd
EndFunc

Func CancelButton()
  ;MsgBox(1, "Closing Script", "No commands were sent!")
  Exit
EndFunc


Func Xbutton()
  Exit
EndFunc

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
  • Recently Browsing   0 members

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