Nunos Posted June 8, 2012 Share Posted June 8, 2012 Hello all I am trying to make a little GUI with a couple buttons on it that will allow someone to exit or continue on and run the little shell command I want. I am having trouble with the OK button currently in the code below it starts the program just fine and runs it but the GUI stays open in the background and doesn't close after the program finishes. Not sure what I am missing. I copied the example out of the help file and tried to modify it to what I am doing. Any help is greatly appreciated. #RequireAdmin #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) ; Change to OnEvent mode $mainwindow = GUICreate("System File Checker", 265, 100) GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked") GUICtrlCreateLabel("You may need your Operating System cd or dvd." & @CRLF & "To continue click OK... or you can close this box.", 25, 10) $okbutton = GUICtrlCreateButton("OK", 80,50, 100) GUICtrlSetOnEvent($okbutton, "OKButton") GUISetState(@SW_SHOW) While 1 Sleep(1000) ; Idle around WEnd Func OKButton() ;MsgBox(0, "GUI Event", "You Pressed OK") ShellExecuteWait("SFC.exe","/scannow","","",@SW_MAXIMIZE) Exit EndFunc Func CLOSEClicked() Exit EndFunc Link to comment Share on other sites More sharing options...
JohnOne Posted June 8, 2012 Share Posted June 8, 2012 I imagine that "SFC.exe" is still running, or does not return a value to indicate it has finished. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Nunos Posted June 8, 2012 Author Share Posted June 8, 2012 Yes SFC.exe runs and returns nothing after it has completed and the only return it would do is a report that says it ran replaced bad files. Link to comment Share on other sites More sharing options...
JohnOne Posted June 8, 2012 Share Posted June 8, 2012 As far as I am aware all executables return a value (exit code) ShellExecuteWait does not return until it recieves that exit code for the launched app. It seems the process is still running. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Nunos Posted June 8, 2012 Author Share Posted June 8, 2012 Do I need to tell it to know the return code and do anything with it? Or should it do it on its own? Maybe I didn't wait long enough? Link to comment Share on other sites More sharing options...
BrewManNH Posted June 8, 2012 Share Posted June 8, 2012 If the ShellExecuteWait won't work correctly with this program, you could use While ProcessExists("sfc.exe") Sleep(10) Wend this will pause the script until that program isn't running any more. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
JohnOne Posted June 8, 2012 Share Posted June 8, 2012 (edited) When you are expecting it to finish, look in taskmanager or similar to see if the process is still running. EDIT: Yes. What BrewManNH said, but use ShellExecute. Edited June 8, 2012 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Nunos Posted June 8, 2012 Author Share Posted June 8, 2012 Yes it was still running. I added the While Process Exists and changed it to shellexecute I think that has it sorted. Is there anyway in which you could have the ok box minimize to like the systray or similar? I worry that if someone can see it there they will try to click it again and get multiple instances of the sfc.exe running. Thank you both for your help and direction its great that you take time out of your days to help people like me. Link to comment Share on other sites More sharing options...
JohnOne Posted June 8, 2012 Share Posted June 8, 2012 GUICtrlSetState along with $GUI_DISABLE should disable the button. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Nunos Posted June 8, 2012 Author Share Posted June 8, 2012 Awesome I will go read up on those thank you again for all of your help. 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