wowmarkb Posted February 8, 2008 Share Posted February 8, 2008 I am making a GUI with buttons that will run .bat files. So far, I have looked in help files/other scripts and cannot find how to say "when the "so and so" button is clicked, run this .bat file (example- file named "ip.bat"- that checks IP Address)".Looks like maybe I found the right code to modify in Online Docs under "GUISetOnEvent " at: http://www.autoitscript.com/autoit3/docs/f...ISetOnEvent.htm ---------------#include <GUIConstants.au3>Opt("GUICoordMode",2)Opt("GUIResizeMode", 1)Opt("GUIOnEventMode", 1)$parent1 = GUICreate("Parent1")GUISetOnEvent($GUI_EVENT_CLOSE, "SpecialEvents")GUISetOnEvent($GUI_EVENT_MINIMIZE, "SpecialEvents")GUISetOnEvent($GUI_EVENT_RESTORE, "SpecialEvents")$ok1 = GUICtrlCreateButton ("OK", 10, 30, 50)GUICtrlSetOnEvent(-1, "OKPressed")$cancel1 = GUICtrlCreateButton ( "Cancel", 0, -1)GUICtrlSetOnEvent(-1, "CancelPressed")GUISetState(@SW_SHOW); Just idle aroundWhile 1 Sleep(10)Wend; ENDFunc OKPressed() MsgBox(0, "OK Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE)EndFuncFunc CancelPressed() MsgBox(0, "Cancel Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE)EndFuncFunc SpecialEvents() Select Case @GUI_CTRLID = $GUI_EVENT_CLOSE MsgBox(0, "Close Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) Exit Case @GUI_CTRLID = $GUI_EVENT_MINIMIZE MsgBox(0, "Window Minimized", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) Case @GUI_CTRLID = $GUI_EVENT_RESTORE MsgBox(0, "Window Restored", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE) EndSelect EndFunc---------------Question 1: If I only needed one button ("OK"), can I remove these lines?:$cancel1 = GUICtrlCreateButton ( "Cancel", 0, -1)GUICtrlSetOnEvent(-1, "CancelPressed")Func CancelPressed() MsgBox(0, "Cancel Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE)EndFuncFunc CancelPressed() MsgBox(0, "Cancel Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE)EndFunc---------------Question 2: How do I tell it to run the "ip.bat" file once the "OK" button (which I will rename to "Check IP Address") is clicked?I think the answer is to modify this line, right?:Func OKPressed() MsgBox(0, "OK Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE)EndFunc---------------Thanks,Mark Link to comment Share on other sites More sharing options...
Zedna Posted February 8, 2008 Share Posted February 8, 2008 (edited) A1: Yes.A2: Yes.:-)Look at FAQ #5 Edited February 8, 2008 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
wowmarkb Posted February 8, 2008 Author Share Posted February 8, 2008 I think I just plug in this lne: RunWait(@COMSPEC & " /c ip.bat") before the EndFunc, right? ------ Func OKPressed() MsgBox(0, "OK Pressed", "ID=" & @GUI_CTRLID & " WinHandle=" & @GUI_WINHANDLE & " CtrlHandle=" & @GUI_CTRLHANDLE) RunWait(@COMSPEC & " /c ip.bat") EndFunc ----- Thanks, Mark Link to comment Share on other sites More sharing options...
PsaltyDS Posted February 8, 2008 Share Posted February 8, 2008 How to run bat file...With Bat computer, of course:Sorry, couldn't resist... hondafrank 1 Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
wowmarkb Posted February 8, 2008 Author Share Posted February 8, 2008 With Bat computer, of course:Sorry, couldn't resist... LOLHey, wait...I remember watching that show...Live!Now, I'm depressed...so many years... Mark 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