Sign in to follow this  
Followers 0
Nunos

GUI Buttons

10 posts in this topic

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

Share this post


Link to post
Share on other sites



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.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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 Gude
How 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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Awesome I will go read up on those thank you again for all of your help.

Share this post


Link to post
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
Sign in to follow this  
Followers 0