Jump to content

Func() under Opt("GUIOnEventMode", 1) question.


schilbiz
 Share

Recommended Posts

The below code works but I am trying to implement it as a Func() under Opt("GUIOnEventMode", 1) What would I need to add to it to make it work? I am adding this to a script that already has Opt("GUIOnEventMode", 1) and functions declared.

#include <GUIConstants.au3>

GUICreate("My GUI",400,200)

$I_Machine = GUICtrlCreateInput("", 10,10,100,100)
$list = GUICtrlCreateList("",200,10,100)
GUICtrlSetData($list, "231461oyiky")
GUICtrlSetData($list, "sadfafiky")
GUICtrlSetData($list, "234234yiky")

$selectbutton = GUICtrlCreateButton ("Select Machine", 200,120,100)

GUISetState()

While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    $one = GUICtrlRead ($list)
    If $msg = $selectbutton Then
        GUICtrlSetData ($I_Machine , "")
        GUICtrlSetData ($I_Machine ,$one)
    EndIf
WEndoÝ÷ Ù8b±Ú²}ý·
+«­¢+ÙÕ¹M1
Q   ÕÑѽ¸ ¤)]¡¥±Ä($ÀÌØíµÍôU%Ñ5Í ¤(%ÀÌØíµÍôÀÌØíU%}Y9Q}
1=MQ¡¸á¥Ñ1½½À(ÀÌØí½¹ôU%
ÑɱI ÀÌØí±¥ÍФ(%ÀÌØíµÍôÀÌØíͱÑÕÑѽ¸Q¡¸(U%
ÑɱMÑÑ ÀÌØí%}5¡¥¹°ÅÕ½ÐìÅÕ½Ðì¤(U%
ÑɱMÑÑ ÀÌØí%}5¡¥¹°ÀÌØí½¹¤(¹%)]¹)¹Õ¹

Edit: had to change some stuff and then the code gets scrambled when I try a full edit..

Edited by schilbiz
Link to comment
Share on other sites

Here is the script that I am trying to add it to so you get a better idea what I am trying.

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

$GUI = GUICreate("Remote Tools", 490, 320, 200, 150)

#region ;GUI Groups
$LG_Machine = GUICtrlCreateGroup("Machine", 5, 10, 240, 75)
GUICtrlSetFont($LG_Machine, 11, 400, "", "Times New Roman")
$LG_Process = GUICtrlCreateGroup("Process", 5, 85, 240, 75)
GUICtrlSetFont($LG_Process, 11, 400, "", "Times New Roman")
$LG_Command = GUICtrlCreateGroup("Command", 5, 210, 240, 75)
GUICtrlSetFont($LG_Command, 11, 400, "", "Times New Roman")
$LG_Reference = GUICtrlCreateGroup("Reference List", 250, 10, 235, 275) 
GUICtrlSetFont($LG_Reference, 11, 400, "", "Times New Roman")
#endregion

#region ;Labels
$L_Machine = GUICtrlCreateLabel("Machine Name or IP Address.", 15, 30, 220, 16, $SS_SUNKEN)
$L_Process = GUICtrlCreateLabel("Process to Kill.", 15, 105, 220, 16, $SS_SUNKEN)
GUICtrlSetFont($L_Process, 9, 400, "", "Times New Roman")
GUICtrlSetColor($L_Process, "0x000000")
$BL_Process = GUICtrlCreateLabel("(Machine + Process)", 120, 170, 120, 16)
GUICtrlSetColor($BL_Process, "0xff0000")
$L_Command = GUICtrlCreateLabel("Shutdown Command.", 15, 230, 220, 16, $SS_SUNKEN)
GUICtrlSetFont($L_Command, 9, 400, "", "Times New Roman")
GUICtrlSetColor($L_Command, "0x000000")
$BL_Command = GUICtrlCreateLabel("(Machine + Command)", 120, 295, 120, 16)
GUICtrlSetColor($BL_Command, "0xff0000")
#endregion

#region ;Input Boxes
$I_Machine = GUICtrlCreateInput("", 15, 55, 220, 21)
$I_Process = GUICtrlCreateCombo("", 15, 130, 220, 21) ;add $CBS_DROPDOWNLIST to limit input
GUICtrlSetData(-1," |excel.exe|outlook.exe")
$I_Command = GUICtrlCreateCombo("", 15, 255, 220, 21) ; add $CBS_DROPDOWNLIST to limit input edit
GUICtrlSetData(-1," |0=Log Off|0+4=Forced Log Off|1=Shutdown|1+4=Forced Shutdown|2=Reboot|2+4=Forced Reboot|8=Power Off|8+4=Forced Power Off")
#endregion

#region ;Computer ($list)
$list = GUICtrlCreateList("", 255, 35, 225, 240)
GUICtrlSetData($list, "213412 ")
GUICtrlSetData($list, "auikasd")
GUICtrlSetData($list, "231461oyiky")
GUICtrlSetData($list, "2314asdtkkkk")
GUICtrlSetData($list, "jkayit")
GUICtrlSetData($list, "qw3487o;")
GUICtrlSetData($list, "asu;ioser")
GUICtrlSetData($list, "aetyi;lera")
GUICtrlSetData($list, "awet;aet")
GUICtrlSetData($list, "dsagu,kil")
GUICtrlSetData($list, "sadfyukjykj")
GUICtrlSetData($list, "sraylou")
GUICtrlSetData($list, "asddfdgdf")
GUICtrlSetData($list, "dddddd")
GUICtrlSetData($list, "dstserts")
GUICtrlSetData($list, "wrerrereer")
#endregion

#region ;Buttons
$processbutton = GUICtrlCreateButton("Execute Process", 15, 165, 100) ;Ok button name and location.
$commandbutton = GUICtrlCreateButton("Execute Command", 15, 290, 100)
$selectbutton = GUICtrlCreateButton("Select Machine", 265, 290, 100) 
$cancelbutton = GUICtrlCreateButton("Cancel", 375, 290, 100) ;Cancel button name and location.
#endregion

;Decalres as a function.
GUICtrlSetOnEvent($processbutton, "PROCESSButton") 
GUICtrlSetOnEvent($commandbutton, "COMMANDButton")
GUICtrlSetOnEvent($selectbutton, "SELECTButton")
GUICtrlSetOnEvent($cancelbutton, "CANCELButton")
GUISetOnEvent($GUI_EVENT_CLOSE, "XButton")
;GUICtrlSetState($I_Process, $GUI_FOCUS)
;GUISetState(@SW_SHOW)
GUISetState()

While 1
    sleep(200)
WEnd

#region ;PROCESSButton
Func PROCESSButton()
$r_Machine = GuiCtrlRead($I_Machine) 
$r_Process = GuiCtrlRead($I_Process)
$runString = StringFormat("taskkill /s %s /u domain\admin /p pass /im %s", $r_Machine, $r_Process) ;establishes $runString - tasskill.exe w/parameters.
$run = Run($runString, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;Runs the variable $runString.

While 1
    $line = StdoutRead($run) ;Standard output readline based off of actions of variable $line which is determined by a "Windows" operator.
    If @error Then ExitLoop
    MsgBox(0, "Note:", $line) ;Output information of what occurs.
    MsgBox(0, "Success:", "Remote Tools will now close.") 
    Exit
Wend

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

#region ;COMMANDButton
Func COMMANDbutton(ByRef $I_Machine, ByRef $I_Command)
    Local $wbemFlagReturnImmediately, $wbemFlagForwardOnly, $objWMIService, $colItems, $objItem
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $objWMIService = ObjGet("winmgmts:\\" & $I_Machine & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT Name From Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    ; 0=Log Off|0+4=Forced Log Off|1=Shutdown|1+4=Forced Shutdown|2=Reboot|2+4=Forced Reboot|8=Power Off|8+4=Forced Power Off
    For $objItem in $colItems
        $objItem.Win32ShutDown($I_Command)
    Next
EndFunc
#endregion


#region ;SELECTButton
Func SELECTButton()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    $one = GUICtrlRead ($list)
    If $msg = $selectbutton Then
        GUICtrlSetData ($I_Machine , "")
        GUICtrlSetData ($I_Machine ,$one)
    EndIf
Wend
EndFunc
#endregion

#region ;Exit Functions
Func CANCELButton()
  MsgBox(0, "Closing Script", "No commands were sent!", 1.5) 
  Exit
EndFunc

Func Xbutton() ;Exits
  Exit
EndFunc
#endregion
Edited by schilbiz
Link to comment
Share on other sites

Here is the script that I am trying to add it to so you get a better idea what I am trying.

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

$GUI = GUICreate("Remote Tools", 490, 320, 200, 150)

#region ;GUI Groups
$LG_Machine = GUICtrlCreateGroup("Machine", 5, 10, 240, 75)
GUICtrlSetFont($LG_Machine, 11, 400, "", "Times New Roman")
$LG_Process = GUICtrlCreateGroup("Process", 5, 85, 240, 75)
GUICtrlSetFont($LG_Process, 11, 400, "", "Times New Roman")
$LG_Command = GUICtrlCreateGroup("Command", 5, 210, 240, 75)
GUICtrlSetFont($LG_Command, 11, 400, "", "Times New Roman")
$LG_Reference = GUICtrlCreateGroup("Reference List", 250, 10, 235, 275) 
GUICtrlSetFont($LG_Reference, 11, 400, "", "Times New Roman")
#endregion

#region ;Labels
$L_Machine = GUICtrlCreateLabel("Machine Name or IP Address.", 15, 30, 220, 16, $SS_SUNKEN)
$L_Process = GUICtrlCreateLabel("Process to Kill.", 15, 105, 220, 16, $SS_SUNKEN)
GUICtrlSetFont($L_Process, 9, 400, "", "Times New Roman")
GUICtrlSetColor($L_Process, "0x000000")
$BL_Process = GUICtrlCreateLabel("(Machine + Process)", 120, 170, 120, 16)
GUICtrlSetColor($BL_Process, "0xff0000")
$L_Command = GUICtrlCreateLabel("Shutdown Command.", 15, 230, 220, 16, $SS_SUNKEN)
GUICtrlSetFont($L_Command, 9, 400, "", "Times New Roman")
GUICtrlSetColor($L_Command, "0x000000")
$BL_Command = GUICtrlCreateLabel("(Machine + Command)", 120, 295, 120, 16)
GUICtrlSetColor($BL_Command, "0xff0000")
#endregion

#region ;Input Boxes
$I_Machine = GUICtrlCreateInput("", 15, 55, 220, 21)
$I_Process = GUICtrlCreateCombo("", 15, 130, 220, 21) ;add $CBS_DROPDOWNLIST to limit input
GUICtrlSetData(-1," |excel.exe|outlook.exe")
$I_Command = GUICtrlCreateCombo("", 15, 255, 220, 21) ; add $CBS_DROPDOWNLIST to limit input edit
GUICtrlSetData(-1," |0=Log Off|0+4=Forced Log Off|1=Shutdown|1+4=Forced Shutdown|2=Reboot|2+4=Forced Reboot|8=Power Off|8+4=Forced Power Off")
#endregion

#region ;Computer ($list)
$list = GUICtrlCreateList("", 255, 35, 225, 240)
GUICtrlSetData($list, "213412 ")
GUICtrlSetData($list, "auikasd")
GUICtrlSetData($list, "231461oyiky")
GUICtrlSetData($list, "2314asdtkkkk")
GUICtrlSetData($list, "jkayit")
GUICtrlSetData($list, "qw3487o;")
GUICtrlSetData($list, "asu;ioser")
GUICtrlSetData($list, "aetyi;lera")
GUICtrlSetData($list, "awet;aet")
GUICtrlSetData($list, "dsagu,kil")
GUICtrlSetData($list, "sadfyukjykj")
GUICtrlSetData($list, "sraylou")
GUICtrlSetData($list, "asddfdgdf")
GUICtrlSetData($list, "dddddd")
GUICtrlSetData($list, "dstserts")
GUICtrlSetData($list, "wrerrereer")
#endregion

#region ;Buttons
$processbutton = GUICtrlCreateButton("Execute Process", 15, 165, 100) ;Ok button name and location.
$commandbutton = GUICtrlCreateButton("Execute Command", 15, 290, 100)
$selectbutton = GUICtrlCreateButton("Select Machine", 265, 290, 100) 
$cancelbutton = GUICtrlCreateButton("Cancel", 375, 290, 100) ;Cancel button name and location.
#endregion

;Decalres as a function.
GUICtrlSetOnEvent($processbutton, "PROCESSButton") 
GUICtrlSetOnEvent($commandbutton, "COMMANDButton")
GUICtrlSetOnEvent($selectbutton, "SELECTButton")
GUICtrlSetOnEvent($cancelbutton, "CANCELButton")
GUISetOnEvent($GUI_EVENT_CLOSE, "XButton")
;GUICtrlSetState($I_Process, $GUI_FOCUS)
;GUISetState(@SW_SHOW)
GUISetState()

While 1
    sleep(200)
WEnd

#region ;PROCESSButton
Func PROCESSButton()
$r_Machine = GuiCtrlRead($I_Machine) 
$r_Process = GuiCtrlRead($I_Process)
$runString = StringFormat("taskkill /s %s /u domain\admin /p pass /im %s", $r_Machine, $r_Process) ;establishes $runString - tasskill.exe w/parameters.
$run = Run($runString, "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) ;Runs the variable $runString.

While 1
    $line = StdoutRead($run) ;Standard output readline based off of actions of variable $line which is determined by a "Windows" operator.
    If @error Then ExitLoop
    MsgBox(0, "Note:", $line) ;Output information of what occurs.
    MsgBox(0, "Success:", "Remote Tools will now close.") 
    Exit
Wend

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

#region ;COMMANDButton
Func COMMANDbutton(ByRef $I_Machine, ByRef $I_Command)
    Local $wbemFlagReturnImmediately, $wbemFlagForwardOnly, $objWMIService, $colItems, $objItem
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $objWMIService = ObjGet("winmgmts:\\" & $I_Machine & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery("SELECT Name From Win32_OperatingSystem", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    ; 0=Log Off|0+4=Forced Log Off|1=Shutdown|1+4=Forced Shutdown|2=Reboot|2+4=Forced Reboot|8=Power Off|8+4=Forced Power Off
    For $objItem in $colItems
        $objItem.Win32ShutDown($I_Command)
    Next
EndFunc
#endregion


#region ;SELECTButton
Func SELECTButton()
While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
    $one = GUICtrlRead ($list)
    If $msg = $selectbutton Then
        GUICtrlSetData ($I_Machine , "")
        GUICtrlSetData ($I_Machine ,$one)
    EndIf
Wend
EndFunc
#endregion

#region ;Exit Functions
Func CANCELButton()
  MsgBox(0, "Closing Script", "No commands were sent!", 1.5) 
  Exit
EndFunc

Func Xbutton() ;Exits
  Exit
EndFunc
#endregion
Func SELECTButton()
    $one = GUICtrlRead ($list)
    GUICtrlSetData ($I_Machine ,$one)
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Thanks GEOSoft that made it work.

And to think it was something that simple, an obvious oversight on my part.. I was thinking of much more complicated solutions.

We all make that mistake. Often the more simple the solution the more we are apt to overlook it. In my case I have a simple mind so the solution came easily.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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...