Jump to content

Recommended Posts

Posted (edited)

This is my first attempt to create a GUI, and I must say its very exiting to discover such an easy way to create something out of nothing. I tried doing the same thing with Visual basic, but that was WAY too complicated.

With autoit, so far I have learned how to create buttons, how to start an application using a button, how to hide the command prompt window from appearing, when executing a command and creating menus/submenus.

So, my first project is to create a web server control GUI. Someting lke this.

Posted Image

What I don't know how to do, is make the progress bar indicate when Apache and MySQL services are starting and stopping. I also need some kind of indicator to show if Apache and MySQL are started or stopped. Maybe a green and a red dot or something. And last, how do Imake the html files open with the deafult html viewer insted of IE like I have it configured now?

Posted Image

Posted Image

This is what i have so far.

#include <GuiConstants.au3>

If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

GuiCreate("CYCMS WebServer v0.21", 270, 250, 400,250 ,BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Filemenu = GuiCtrlCreateMenu ("File")
$Exititem = GuiCtrlCreateMenuitem ("Exit",$Filemenu)

$Toolmenu = GuiCtrlCreateMenu ("Tools")
$Toolitem = GuiCtrlCreateMenuitem ("IP Detect",$Toolmenu)

$Helpmenu = GuiCtrlCreateMenu ("Help")
$Helpitem = GuiCtrlCreateMenuitem ("Help Topics",$Helpmenu)
$Aboutitem = GuiCtrlCreateMenuitem ("About CYCMS WebServer",$Helpmenu)
$Separator1 = GuiCtrlCreateMenuitem ("",$Helpmenu)
$Homepageitem = GuiCtrlCreateMenuitem ("CYCMS WebServer Homepage",$Helpmenu)

$Button1 = GuiCtrlCreateButton("Start Apache", 56, 40, 75, 25)
$Button2 = GuiCtrlCreateButton("Stop Apache", 56, 72, 75, 25)
$Button3 = GuiCtrlCreateButton("Start MySQL", 136, 40, 75, 25)
$Button4 = GuiCtrlCreateButton("Stop MySQL", 136, 72, 75, 25)
$Button5 = GuiCtrlCreateButton("Configure PHPMyAdmin", 136, 160, 123, 25)
$Button6 = GuiCtrlCreateButton("Configure MySQL", 136, 128, 123, 25)
$Button7 = GuiCtrlCreateButton("Configure Apache", 8, 128, 123, 25)
$Button8 = GuiCtrlCreateButton("Configure PHP", 8, 160, 123, 25)
$Button9 = GuiCtrlCreateButton("Open Localhost", 8, 190, 123, 25)
$Button10 = GuiCtrlCreateButton("Open PHPMyAdmin", 136, 190, 123, 25)

$ProgressBar1 = GuiCtrlCreateProgress(56, 104, 158, 16)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        
        Case $MSG = $Button1
        Run(@ComSpec & " /c " & 'net start Apache2', "", @SW_HIDE)
        
        Case $MSG = $Button2
        Run(@ComSpec & " /c " & 'net stop Apache2', "", @SW_HIDE)
        
        Case $MSG = $Button3
        Run(@ComSpec & " /c " & 'net start MySQL', "", @SW_HIDE)
        
        Case $MSG = $Button4
        Run(@ComSpec & " /c " & 'net stop MySQL', "", @SW_HIDE)
        
        Case $MSG = $Button5
        Run("C:\webserver\services\3rdparty\Wordpad.exe C:\webserver\wwwroot\phpmyadmin\config.default.php")
        
        Case $MSG = $Button6
        Run("C:\webserver\services\3rdparty\Wordpad.exe C:\WINDOWS\my.ini")
        
        Case $MSG = $Button7
        Run("C:\webserver\services\3rdparty\Wordpad.exe C:\webserver\Apache2\conf\httpd.conf")
        
        Case $MSG = $Button8
        Run("C:\webserver\services\3rdparty\Wordpad.exe C:\WINDOWS\php.ini")
        
        Case $MSG = $Button9
        Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE http://localhost/")
                
        Case $MSG = $Button10
        Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE http://localhost/phpmyadmin/")
        
        Case $MSG = $Exititem
        ExitLoop
        
        Case $MSG = $Toolitem
        Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE http://www.whatismyip.com/")
        
        Case $MSG = $Helpitem
        Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE C:\webserver\services\htmlhelp\index.html")
        
        Case $MSG = $Aboutitem
        Msgbox(0,"About CYCMS WebServer","CYCMS WebServer Version 0.21")
        
        Case $MSG = $Homepageitem
        Run("C:\Program Files\Internet Explorer\IEXPLORE.EXE http://www.cypruscms.com/")
        
        Case Else
;;;
    EndSelect
WEnd
Exit

Thank you.

Edited by Nucleus
Posted

I guess to create an indicator, you would need to create a (blank if you want) label of the correct size, and use GUICtrlSetBkColor to set the background colour to green or red.

Not sure about a progress bar for starting services - how would you tell how much progress had been made? (Maybe use a timer if it takes a repeatable amount of time to start the service..?)

As for opening websites with the default browser, use this code:

Run (@ComSpec & '/c start http://www.site.com/', "", @SW_HIDE)

You can do this with any protocol that has a defined handler, or documents.

Hope that helps

ben

Posted (edited)

When using this

Run (@ComSpec & '/c start http://www.site.com/', "", @SW_HIDE)

I get the following error.

I found the following to be more reliable

Run (@ComSpec & '/c start explorer http://www.site.com/', "", @SW_HIDE)
Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted

I have found a way to solve the progress bar problem, by using an example I found on this site.

ProgressOn("Processing Service", "Status...", "0 percent")
For $i = 10 to 100 step 10
    sleep(300)
    ProgressSet( $i, $i & " percent")
Next
ProgressSet(100 , "Done", "Complete")
sleep(500)
ProgressOff()

Compiled as exe, and run when a Start/Stop Service button is pressed. So that it appears as if the process is starting or stopping.

eg.

Case $MSG = $Button1
Run(@ComSpec & " /c " & 'net start Apache2', "", @SW_HIDE)
Run("ProgressBar.exe")

However if the process fails to start, it will not report it, that's why I need to implement the red/green indicators. I haven't found a way to do it though, because of my minimal experience with autoit.

Examples anyone?

Posted

I am asking about somehow detecting if a service is started or stopped, and displaying a red or green light, depending on the status of the service.

Posted (edited)

#include <GUIConstants.au3>

GUICreate("My GUI") ; will create a dialog box that when displayed is centered

$red_lbl = GUICtrlCreateLabel("", 10, 10, 10, 10, $SS_SUNKEN)
GUICtrlSetBkColor($red_lbl, 0xEE0000)
$green_lbl = GUICtrlCreateLabel("", 10, 10, 10, 10, $SS_SUNKEN)
GUICtrlSetBkColor($green_lbl, 0x00CD00)
GUICtrlSetState($green_lbl, $GUI_HIDE)
$btn_toggle = GUICtrlCreateButton("Status", 10, 30, 90)
GUISetState()    ; will display an empty dialog box

; Run the GUI until the dialog is closed
Do
   $msg = GUIGetMsg()
   If $msg = $btn_toggle Then
      _GetServiceStatus(@ComputerName, "Symantec Antivirus")
   EndIf
Until $msg = $GUI_EVENT_CLOSE

Func _GetServiceStatus($s_Machine, $Service)
   Const $wbemFlagReturnImmediately = 0x10
   Const $wbemFlagForwardOnly = 0x20
   Local $objWMIService = ObjGet("winmgmts:\\" & $s_Machine & "\root\CIMV2")
   If @error Then
      MsgBox(16, "_RetrieveServices", "ObjGet Error: winmgmts")
      Return
   EndIf
   $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_Service", "WQL", _
         $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
   If @error Then
      MsgBox(16, "_RetrieveServices", "ExecQuery Error: SELECT * FROM Win32_Service")
      Return
   EndIf
   If IsObj($colItems) Then
      For $objItem In $colItems
         If StringUpper($objItem.Name) = StringUpper($Service) Then
            If $objItem.State = "Stopped" Then
               GUICtrlSetState($green_lbl, $GUI_HIDE)
               GUICtrlSetState($red_lbl, $GUI_SHOW)
            Else
               GUICtrlSetState($red_lbl, $GUI_HIDE)
               GUICtrlSetState($green_lbl, $GUI_SHOW)
            EndIf
         EndIf
      Next
   EndIf
EndFunc  ;==>_GetServiceStatus

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Posted

It seems to be working very nice. The only problem is that, to get the status of the service, I have to press the button. It should be able to automatically get the status of the service, when I start or stop a service by clicking on the buttons on this form.

#include <GuiConstants.au3>

If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

GuiCreate("CYCMS WebServer v0.21",350,350)

$Filemenu = GuiCtrlCreateMenu ("File")
$Exititem = GuiCtrlCreateMenuitem ("Exit",$Filemenu)

$Toolmenu = GuiCtrlCreateMenu ("Tools")
$Toolitem = GuiCtrlCreateMenuitem ("IP Detect",$Toolmenu)

$Helpmenu = GuiCtrlCreateMenu ("Help")
$Helpitem = GuiCtrlCreateMenuitem ("Help Topics",$Helpmenu)
$Aboutitem = GuiCtrlCreateMenuitem ("About CYCMS WebServer",$Helpmenu)
$Separator1 = GuiCtrlCreateMenuitem ("",$Helpmenu)
$Homepageitem = GuiCtrlCreateMenuitem ("CYCMS WebServer Homepage",$Helpmenu)

$Button1 = GuiCtrlCreateButton("Start Apache", 100, 40, 75, 25)
$Button2 = GuiCtrlCreateButton("Stop Apache", 100, 72, 75, 25)
$Button3 = GuiCtrlCreateButton("Start MySQL", 177, 40, 75, 25)
$Button4 = GuiCtrlCreateButton("Stop MySQL", 177, 72, 75, 25)
$Button5 = GuiCtrlCreateButton("Configure PHPMyAdmin", 177, 160, 125, 25)
$Button6 = GuiCtrlCreateButton("Configure MySQL", 177, 128, 125, 25)
$Button7 = GuiCtrlCreateButton("Configure Apache", 50, 128, 125, 25)
$Button8 = GuiCtrlCreateButton("Configure PHP", 50, 160, 125, 25)
$Button9 = GuiCtrlCreateButton("Open Localhost", 50, 190, 125, 25)
$Button10 = GuiCtrlCreateButton("Open PHPMyAdmin", 177, 190, 125, 25)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        
        Case $MSG = $Button1
        Run(@ComSpec & " /c " & 'net start Apache2', "", @SW_HIDE)
        Run("ProgressBar.exe")
        
        Case $MSG = $Button2
        Run(@ComSpec & " /c " & 'net stop Apache2', "", @SW_HIDE)
        Run("ProgressBar.exe")
        
        Case $MSG = $Button3
        Run(@ComSpec & " /c " & 'net start MySQL', "", @SW_HIDE)
        Run("ProgressBar.exe")
        
        Case $MSG = $Button4
        Run(@ComSpec & " /c " & 'net stop MySQL', "", @SW_HIDE)
        Run("ProgressBar.exe")
        
        Case $MSG = $Button5
        Run("C:\webserver\services\3rdparty\Wordpad.exe C:\webserver\wwwroot\phpmyadmin\config.default.php")
        
        Case $MSG = $Button6
        Run("C:\webserver\services\3rdparty\Wordpad.exe C:\WINDOWS\my.ini")
        
        Case $MSG = $Button7
        Run("C:\webserver\services\3rdparty\Wordpad.exe C:\webserver\Apache2\conf\httpd.conf")
        
        Case $MSG = $Button8
        Run("C:\webserver\services\3rdparty\Wordpad.exe C:\WINDOWS\php.ini")
        
        Case $MSG = $Button9
        Run (@ComSpec & ' /c start explorer http://localhost/', "", @SW_HIDE)
                
        Case $MSG = $Button10
        Run (@ComSpec & ' /c start explorer http://localhost/phpmyadmin/', "", @SW_HIDE)
        
        Case $MSG = $Toolitem
        Run (@ComSpec & ' /c start explorer http://www.whatismyip.com/', "", @SW_HIDE)
        
        Case $MSG = $Helpitem
        Run (@ComSpec & ' /c start explorer C:\webserver\services\htmlhelp\index.html', "", @SW_HIDE)
        
        Case $MSG = $Aboutitem
        Msgbox(0,"About CYCMS WebServer","CYCMS WebServer Version 0.21")
        
        Case $MSG = $Homepageitem
        Run (@ComSpec & ' /c start explorer http://www.cypruscms.com/', "", @SW_HIDE)
        
        Case $MSG = $Exititem
        ExitLoop
        
        Case Else
    ;;;
    EndSelect
WEnd
Exit
Posted

Come to think of it, the question should be, how do I combine your code, with mine?

some code for you to look at would be in My Admin Tool (in my signature), look for _SetServiceState function which should help you out alot.

Gary

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

  • 2 weeks later...

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
×
×
  • Create New...