Jump to content
pranaynanda

Msgbox not Showing when GUI Runs

Recommended Posts

pranaynanda

I'm trying to run this code:

#include <GuiListView.au3>
#include <GUIConstants.au3>

Dim $Services
Dim $ServicesList
#cs
While 1
    CheckService()
    Sleep(30000)    ; sleep 30 seconds
WEnd
#ce
;#cs
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Tab1 = GUICtrlCreateTab(0, 48, 609, 385)
$TabSheet1 = GUICtrlCreateTabItem("Running Services")
$ListView1 = GUICtrlCreateListView("Service Name|Status", 8, 72, 593, 281, -1, BitOR($LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT))
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 0, 300)
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 1, 288)


$Button1 = GUICtrlCreateButton("Stop Services", 464, 376, 129, 33)
$TabSheet2 = GUICtrlCreateTabItem("Stopped Services")
GUICtrlSetState(-1,$GUI_SHOW)
$ListView2 = GUICtrlCreateListView("Service Name|Status", 8, 72, 593, 281, -1, BitOR($LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT))
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 0, 300)
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 1, 288)

$Button2 = GUICtrlCreateButton("Start Services", 464, 376, 129, 33)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
;#ce

;$Tab1 = GUICtrlCreateTab(16, 8, 601, 377)
;$TabSheet1 = GUICtrlCreateTabItem("Running Services")
;$ListView1 = GUICtrlCreateListView("Service Name", 24, 40, 582, 334)
;_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES))

;$ServiceName = "wuauserv"
    Local $Services = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
    Local $ServicesList = $Services.ExecQuery("SELECT * FROM Win32_Service")
    If IsObj($ServicesList) then
        For $Services in $ServicesList
            ;If $Services.Name = $ServiceName Then
             ;   if $Services.State = "Running" Then
                   MsgBox(8192,"Hello", $Services.Name & $Services.State,0,$Form1)
                   ;GUICtrlCreateListViewItem( $Services.Name & "|" & $Services.State , $ListView1)
                    ;Run (@ComSpec & " /c " & 'net stop wuauserv')
              ;  EndIf
            ;EndIf
        Next
    EndIf
;EndFunc

But the msgbox does turn up when GUI runs. However, if I comment the GUI section, it works perfectly fine. Please help.

Share this post


Link to post
Share on other sites
InunoTaishou

Here's the logic behind your script.

Create a gui, add some control, go to infinite while loop that stops execution of everything below it and just checks for the close event, get the services on the computer.

Try this

#include <GuiListView.au3>
#include <GUIConstants.au3>

Dim $Services
Dim $ServicesList
#cs
    While 1
    CheckService()
    Sleep(30000)    ; sleep 30 seconds
    WEnd
#ce
;#cs
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 615, 438, 192, 124)
$Tab1 = GUICtrlCreateTab(0, 48, 609, 385)
$TabSheet1 = GUICtrlCreateTabItem("Running Services")
$ListView1 = GUICtrlCreateListView("Service Name|Status", 8, 72, 593, 281, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 0, 300)
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 1, 288)


$Button1 = GUICtrlCreateButton("Stop Services", 464, 376, 129, 33)
$TabSheet2 = GUICtrlCreateTabItem("Stopped Services")
GUICtrlSetState(-1, $GUI_SHOW)
$ListView2 = GUICtrlCreateListView("Service Name|Status", 8, 72, 593, 281, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 0, 300)
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 1, 288)

$Button2 = GUICtrlCreateButton("Start Services", 464, 376, 129, 33)
GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

AdlibRegister(CheckServices, 1000)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd
;#ce

;$Tab1 = GUICtrlCreateTab(16, 8, 601, 377)
;$TabSheet1 = GUICtrlCreateTabItem("Running Services")
;$ListView1 = GUICtrlCreateListView("Service Name", 24, 40, 582, 334)
;_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES))

;$ServiceName = "wuauserv"
Func CheckServices()
    Local $Services = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
    Local $ServicesList = $Services.ExecQuery("SELECT * FROM Win32_Service")
    If IsObj($ServicesList) Then
        For $Services In $ServicesList
            ;If $Services.Name = $ServiceName Then
            ;   if $Services.State = "Running" Then
            MsgBox(8192, "Hello", $Services.Name & $Services.State, 0, $Form1)
            ;GUICtrlCreateListViewItem( $Services.Name & "|" & $Services.State , $ListView1)
            ;Run (@ComSpec & " /c " & 'net stop wuauserv')
            ;  EndIf
            ;EndIf
        Next
    EndIf
EndFunc   ;==>CheckServices

 

  • Like 1

Share this post


Link to post
Share on other sites
water

That's because you got trapped in the While/WEnd loop. The only way to exit this loop (and to execute the code that follows the loop) is to close the GUI - but this then exits the script.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-06-01 - Version 1.4.9.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-01-27 - Version 1.3.3.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites
pranaynanda

@InunoTaishou THAT WORKED! THANKS!

Func _populate()
    Local $Services = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
    Local $ServicesList = $Services.ExecQuery("SELECT * FROM Win32_Service")
    If IsObj($ServicesList) then
        For $Services in $ServicesList
            ;If $Services.Name = $ServiceName Then
                if $Services.State = "Running" Then
                   ;MsgBox(8192,"Hello", $Services.Name & $Services.State,0,$Form1)
                   GUICtrlCreateListViewItem( $Services.Name & "|" & $Services.State , $ListView1)
                Else
                   GUICtrlCreateListViewItem( $Services.Name & "|" & $Services.State , $ListView2)
                ;Run (@ComSpec & " /c " & 'net stop wuauserv')
                EndIf
            ;EndIf
        Next
    EndIf
EndFunc

I have this now. Any ideas on how can I start or stop services based on their status from the buttons mentioned above? I know I'll have to create 2 functions. I'm not sure about how to put up a proper loop for it.

Edited by pranaynanda
Poor Punctuation

Share this post


Link to post
Share on other sites
InunoTaishou

I'll just leave this here.

 

 

Share this post


Link to post
Share on other sites
pranaynanda

Thank you but I got i to work somehow. A little more help will be really appreciated. I have this now.

#include <GuiListView.au3>
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

#RequireAdmin

Dim $Services
Dim $ServicesList

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Service Manager", 677, 438, 192, 124)

$Label1 = GUICtrlCreateLabel("Service Manager", 8, 0, 235, 46)
GUICtrlSetFont($Label1, 27, 800, 2, "Arial Narrow")
GUICtrlSetColor($Label1, 0x0066CC)

$Tab1 = GUICtrlCreateTab(0, 48, 676, 385)
$TabSheet1 = GUICtrlCreateTabItem("Running Services")
$ListView1 = GUICtrlCreateListView("Service Display Name|Service Name|Status", 2, 72, 670, 281, -1, BitOR($LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT))
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 0, 300)
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 1, 288)
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 2, 88)
$Button1 = GUICtrlCreateButton("Stop Services", 464, 376, 129, 33)

$TabSheet2 = GUICtrlCreateTabItem("Stopped Services")
GUICtrlSetState(-1,$GUI_SHOW)
$ListView2 = GUICtrlCreateListView("Service Display Name|Service Name|Status", 2, 72, 670, 281, -1, BitOR($LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT))
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 0, 300)
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 1, 288)
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 2, 88)
$Button2 = GUICtrlCreateButton("Start Services", 464, 376, 129, 33)



$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Select All", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("Unselect All", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem5 = GUICtrlCreateMenu("Help")
$MenuItem6 = GUICtrlCreateMenuItem("Help Topics", $MenuItem5)
$MenuItem7 = GUICtrlCreateMenuItem("About", $MenuItem5)


GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_populate()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button1
            _start()
         Case $Button2
            _stop()
         Case $MenuItem2
            _selectall()
         Case $MenuItem3
            _UnselectAll()
         Case $MenuItem4
            Exit
        Case $MenuItem6
            _HelpTopics()
        Case $MenuItem7
            _AboutProject()
    EndSwitch
WEnd

Func _populate()
    Global $Services = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
    Global $ServicesList = $Services.ExecQuery("SELECT * FROM Win32_Service")
    If IsObj($ServicesList) then
        For $Services in $ServicesList
            if $Services.State = "Running" Then
               GUICtrlCreateListViewItem( $Services.DisplayName & "|" & $Services.Name & "|" & $Services.State , $ListView1)
            Else
               GUICtrlCreateListViewItem( $Services.DisplayName & "|" & $Services.Name & "|" & $Services.State , $ListView2)
            EndIf
         Next
    EndIf
 EndFunc

Func _start()
   Dim $sArray[1]
   $count = _GUICtrlListView_GetItemCount($ListView1)
    $aCount = 0
    For $i = 1 To $count Step 1
        If _GUICtrlListView_GetItemChecked($ListView1, $i-1)  = True Then
            $sArray[$aCount]=_GUICtrlListView_GetItemText($ListView1, $i - 1, 1)
            ReDim $sArray[UBound($sArray) + 1]
            $aCount += 1
        EndIf
     Next

   ProgressOn("Stop services", "Stopping" & $sArray, "", -1, -1, 16)

   For $i = 1 To UBound($sArray) - 1 Step 1
      $service = $sArray[$i - 1]
      RunWait("net stop " & $service)
      ProgressSet($i / (UBound($sArray) - 1) * 100, Round($i / (UBound($sArray) - 1) * 100, 0) & "%", "Stopping" & $service, "Stopping " & $i & " of " & UBound($sArray) - 1)
   Next
   Sleep(5000)
   ProgressOff()
   _populate()
;   ReDim(_populate())
EndFunc

Func _stop()
   Dim $sArray[1]
   $count = _GUICtrlListView_GetItemCount($ListView2)
    $aCount = 0
    For $i = 1 To $count Step 1
        If _GUICtrlListView_GetItemChecked($ListView2, $i - 1) = True Then
            $sArray[$aCount] = _GUICtrlListView_GetItemText($ListView2, $i - 1,1)
            ReDim $sArray[UBound($sArray) + 1]
            $aCount += 1
        EndIf
     Next

      ProgressOn("Starting services", "Starting" & $sArray, "", -1, -1, 16)

   For $i = 1 To UBound($sArray) - 1 Step 1
      $service = $sArray[$i - 1]
      RunWait("net start " & $service)
      ProgressSet($i / (UBound($sArray) - 1) * 100, Round($i / (UBound($sArray) - 1) * 100, 0) & "%", "Starting" & $service, "Starting " & $i & " of " & UBound($sArray) - 1)
   Next
   Sleep(5000)
   ProgressOff()
   _populate()
   ;ReDim(_populate())
EndFunc

Func _selectAll()
    _GUICtrlListView_SetItemChecked($ListView1, - 1, True)
    _GUICtrlListView_SetItemChecked($ListView2, - 1, True)
EndFunc

Func _UnselectAll()
         _GUICtrlListView_SetItemChecked($ListView1, - 1, False)

         _GUICtrlListView_SetItemChecked($ListView2, - 1, False)


EndFunc

Func _HelpTopics()
    $Form2 = GUICreate("Help Topics", 633, 447)
    $Label1 = GUICtrlCreateLabel("", 8, 16, 612, 425)
    GUICtrlSetData(-1, "This Program uses collects all sevices from Windows (services.msc) and categorizes them according to their status (Running or Stopped). It then uses windows net start <servicename> or net stop <servicename> commands to start or stop multiple services based on their selection via checkboxes. ")
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form2)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_HelpTopics

Func _AboutProject()
    $Form3 = GUICreate("About", 413, 196)
    $Label1a = GUICtrlCreateLabel("", 24, 64, 364, 113)
    $Label2a = GUICtrlCreateLabel("Service Manager", 24, 8, 375, 41)
    GUICtrlSetFont(-1, 24, 800, 2, "Arial")
    GUICtrlSetColor(-1, 0x000080)
      GUISetState(@SW_SHOW)
    $aboutData = "This program was written in a programming language called Autoit by" & @CRLF & @CRLF & "GS IT Offshore Team "
   $string = ""
    ;For $i = 1 To UBound($sData) Step 1
        ;$string = $string & @CRLF & $sData[$i - 1] & @CRLF
        GUICtrlSetData($Label1a, $aboutData)
   ;Next

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form3)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_AboutProject

#cs
Imporvement points:
1.Better GUI
2. Auto Refresh
3. Unselect all
4. Progress Bar
5. Silent Mode
#ce

The problem is that after the services are stopped, they are still shown under the running services tab. I want them in stopped, one the command has run. Also, with progress bar, I want to show which current service is being worked on and also show them by number, as in code above. The application seems to crash after the progress bar is done with updating one service. If I remove the main text section of the progress bar, it works fine.

Share this post


Link to post
Share on other sites
AutoBert

change your func _populate to:

Func _populate()
    Global $Services = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
    Global $ServicesList = $Services.ExecQuery("SELECT * FROM Win32_Service")
    If IsObj($ServicesList) then
        _GUICtrlListView_BeginUpdate($ListView1)
        _GUICtrlListView_BeginUpdate($ListView2)
        _GUICtrlListView_DeleteAllItems($ListView1)
        _GUICtrlListView_DeleteAllItems($ListView2)
        
        For $Services in $ServicesList
            if $Services.State = "Running" Then
               GUICtrlCreateListViewItem( $Services.DisplayName & "|" & $Services.Name & "|" & $Services.State , $ListView1)
            Else
               GUICtrlCreateListViewItem( $Services.DisplayName & "|" & $Services.Name & "|" & $Services.State , $ListView2)
            EndIf
         Next
        _GUICtrlListView_EndUpdate($ListView1)
        _GUICtrlListView_EndUpdate($ListView2)
    EndIf
 EndFunc

 

  • Like 1

Share this post


Link to post
Share on other sites
pranaynanda

Thank you! That works incredibly! Now a little help with the progress bar please?

Share this post


Link to post
Share on other sites
pranaynanda

Okay guys, here's what I've got. Because I have it due to the community, I thought of giving it back. It might help some times.

#include <GuiListView.au3>
#include <GUIConstants.au3>
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>

#RequireAdmin

Dim $Services
Dim $ServicesList

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Service Manager", 677, 438, 192, 124)

$Label1 = GUICtrlCreateLabel("Service Manager", 8, 0, 235, 46)
GUICtrlSetFont($Label1, 27, 800, 2, "Arial Narrow")
GUICtrlSetColor($Label1, 0x0066CC)

$Tab1 = GUICtrlCreateTab(0, 48, 676, 385)
$TabSheet1 = GUICtrlCreateTabItem("Running Services")
$ListView1 = GUICtrlCreateListView("Service Display Name|Service Name|Status", 2, 72, 670, 281, -1, BitOR($LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT))
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 0, 300)
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 1, 288)
GUICtrlSendMsg($ListView1, $LVM_SETCOLUMNWIDTH, 2, 88)
$Button1 = GUICtrlCreateButton("Stop Services", 464, 376, 129, 33)

$TabSheet2 = GUICtrlCreateTabItem("Stopped Services")
GUICtrlSetState(-1,$GUI_SHOW)
$ListView2 = GUICtrlCreateListView("Service Display Name|Service Name|Status", 2, 72, 670, 281, -1, BitOR($LVS_EX_GRIDLINES,$LVS_EX_CHECKBOXES,$LVS_EX_FULLROWSELECT))
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 0, 300)
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 1, 288)
GUICtrlSendMsg($ListView2, $LVM_SETCOLUMNWIDTH, 2, 88)
$Button2 = GUICtrlCreateButton("Start Services", 464, 376, 129, 33)



$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Select All", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("Unselect All", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem5 = GUICtrlCreateMenu("Help")
$MenuItem6 = GUICtrlCreateMenuItem("Help Topics", $MenuItem5)
$MenuItem7 = GUICtrlCreateMenuItem("About", $MenuItem5)


GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_populate()
While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button1
            _start()
         Case $Button2
            _stop()
         Case $MenuItem2
            _selectall()
         Case $MenuItem3
            _UnselectAll()
         Case $MenuItem4
            Exit
        Case $MenuItem6
            _HelpTopics()
        Case $MenuItem7
            _AboutProject()
    EndSwitch
WEnd

Func _populate()
    Global $Services = ObjGet("winmgmts:\\" & @ComputerName & "\root\cimv2")
    Global $ServicesList = $Services.ExecQuery("SELECT * FROM Win32_Service")
    If IsObj($ServicesList) then
        _GUICtrlListView_BeginUpdate($ListView1)
        _GUICtrlListView_BeginUpdate($ListView2)
        _GUICtrlListView_DeleteAllItems($ListView1)
        _GUICtrlListView_DeleteAllItems($ListView2)
        For $Services in $ServicesList
            if $Services.State = "Running" Then
               GUICtrlCreateListViewItem( $Services.DisplayName & "|" & $Services.Name & "|" & $Services.State , $ListView1)
            Else
               GUICtrlCreateListViewItem( $Services.DisplayName & "|" & $Services.Name & "|" & $Services.State , $ListView2)
            EndIf
         Next
         _GUICtrlListView_EndUpdate($ListView1)
        _GUICtrlListView_EndUpdate($ListView2)
    EndIf
 EndFunc

Func _start()
   Dim $sArray[1]
   $count = _GUICtrlListView_GetItemCount($ListView1)
    $aCount = 0
    For $i = 1 To $count Step 1
        If _GUICtrlListView_GetItemChecked($ListView1, $i-1)  = True Then
            $sArray[$aCount]=_GUICtrlListView_GetItemText($ListView1, $i - 1, 1)
            ReDim $sArray[UBound($sArray) + 1]
            $aCount += 1
        EndIf
     Next

   ProgressOn("Stop services", "Stopping" & $sArray, "", -1, -1, 16)

   For $i = 1 To UBound($sArray) - 1 Step 1
      $service = $sArray[$i - 1]
      RunWait("net stop " & $service)
      ProgressSet($i / (UBound($sArray) - 1) * 100, Round($i / (UBound($sArray) - 1) * 100, 0) & "%", "Stopping " & $i & " of " & UBound($sArray) - 1)
   Next
   Sleep(5000)
   ProgressOff()
   _populate()
;   ReDim(_populate())
EndFunc

Func _stop()
   Dim $sArray[1]
   $count = _GUICtrlListView_GetItemCount($ListView2)
    $aCount = 0
    For $i = 1 To $count Step 1
        If _GUICtrlListView_GetItemChecked($ListView2, $i - 1) = True Then
            $sArray[$aCount] = _GUICtrlListView_GetItemText($ListView2, $i - 1,1)
            ReDim $sArray[UBound($sArray) + 1]
            $aCount += 1
        EndIf
     Next

      ProgressOn("Starting services", "Starting" & $sArray, "", -1, -1, 16)

   For $i = 1 To UBound($sArray) - 1 Step 1
      $service = $sArray[$i - 1]
      RunWait("net start " & $service)
      ProgressSet($i / (UBound($sArray) - 1) * 100, Round($i / (UBound($sArray) - 1) * 100, 0) & "%", "Starting " & $i & " of " & UBound($sArray) - 1)
   Next
   Sleep(5000)
   ProgressOff()
   _populate()
   ;ReDim(_populate())
EndFunc

Func _selectAll()
    _GUICtrlListView_SetItemChecked($ListView1, - 1, True)
    _GUICtrlListView_SetItemChecked($ListView2, - 1, True)
EndFunc

Func _UnselectAll()
         _GUICtrlListView_SetItemChecked($ListView1, - 1, False)

         _GUICtrlListView_SetItemChecked($ListView2, - 1, False)


EndFunc

Func _HelpTopics()
    $Form2 = GUICreate("Help Topics", 800, 400)
    $Label1 = GUICtrlCreateLabel("", 8, 16, 750, 350)
    GUICtrlSetFont(-1, 24, 300, 2, "Arial")
    GUICtrlSetColor(-1, 0x0066CC)
    $info="This Program uses collects all sevices from Windows (services.msc) and categorizes them according to their status (Running or Stopped)." & @CRLF & @CRLF & "It then uses Windows" & @CRLF & "net start <servicename> or net stop <servicename>" & @CR &"commands to start or stop multiple services based on their selection via checkboxes."
    GUISetState(@SW_SHOW)
   GUICtrlSetData(-1, $info)
    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form2)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_HelpTopics

Func _AboutProject()
    $Form3 = GUICreate("About", 413, 196)
    $Label1a = GUICtrlCreateLabel("", 24, 64, 364, 130)
    $Label2a = GUICtrlCreateLabel("Service Manager", 24, 8, 375, 41)
    GUICtrlSetFont(-1, 24, 900, 2, "Arial")
    GUICtrlSetColor(-1, 0x0066CC)
      GUISetState(@SW_SHOW)
      #cs
    $Form3 = GUICreate("About", 700, 400)
   ; $Label1a = GUICtrlCreateLabel("", 24, 64, 364, 113)
    $Label2a = GUICtrlCreateLabel("Service Manager", 24, 8, 375, 41)
    GUICtrlSetFont($Label2a, 24, 300, 2, "Arial")
    GUICtrlSetColor($Label2a, 0x000080)
    GUISetState(@SW_SHOW)
    #ce
    $aboutData = "This program was written in a programming language called Autoit by"
  ; $string = ""
    ;For $i = 1 To UBound($sData) Step 1
        ;$string = $string & @CRLF & $sData[$i - 1] & @CRLF
        GUICtrlSetData($Label1a, $aboutData)
        GUICtrlSetFont($Label1a, 16, 900, 2, "Arial")
      GUICtrlSetColor($Label1a, 0x0066CC)
   ;Next

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form3)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_AboutProject

#cs
Imporvement points:
1.Better GUI
2. Select remote machine
3. Progress Bar
4. Silent Mode
#ce

My future scope with this is to get it work across all my servers from my location. My thoughts are to make a configuration file to pass the credentials and then further use a switch case statement to get this to work. What are your thoughts?

Share this post


Link to post
Share on other sites
InunoTaishou

Seems redundant to me to have two tabs for running and stopped when in the list view you state whether it's running or stopped. Just my opinion.

As for your progress bar, I couldn't run it because of incorrect number of parameters. But you could use _GUICtrlListView_GetItemTextArray to get a list of all of the services in your list view and go through each one to start/stop them. You'd be better of using _GUICtrlListView_GetItemChecked to go through each item in the list view and add it to an array of services to start/stop if it's checked.

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

  • Similar Content

    • xtcislove
      By xtcislove
      Hello,
      as a start in Autoit i tried something i was missing since im using Autoit. 

      I build a custom MessageBox which has a large amount of custom options and which scales its size on the parameters you set. 

      Aviable Settings:
      -Title
      -Unlimited Buttons
      -Text Color (Buttons, Text)

      -Background Color (Msgbox, Buttons, Label) 

      -Button Timeout
      -Autoclose Timeout
      -Icon (Default, No Icon, Custom)

      -Label/ Button Style. 
      -Transparency

      I tried to keep this as close as i could to a Msgbox i was used too on my batch times.

      After i was ready i realised, @Melba23 probably build a way better msgbox which would have suit my needs enterly, anyway thanks to @Melba23 because i use his Stringsize UDF. 

       
       
      local $Message = _sMsgBox("Test", 6, "Continue?") if @extended <> -1 Then MsgBox(0, @extended, $Message&" Button pressed")  
      ScalingMessageBox.au3
    • SkysLastChance
      By SkysLastChance
      I am having a hard time understanding why this is not working. I was hoping some one could help explain it to me. 
      $tags = $oIE.document.GetElementsByTagName("input") For $tag in $tags $class_value = $tag.GetAttribute("class") If string($class_value) = "fTs-p3298-l0 wplEditControl" Then $target = $tag ExitLoop EndIF Next MsgBox(0,"",$target) If $target = "fTs-p3298-l0 wplEditControl" THEN MsgBox(0,"","itworked") I have tried 
       MsgBox(0,"",$target.Attribute)  MsgBox(0,"",$target.Value)  MsgBox(0,"",$target.InnerText) I would expect to see this in the msgbox
      fTs-p3298-l0 wplEditControl  
    • jasontj
      By jasontj
      Hello.  I'm working on converting another script from IE to Firefox.  I can't seem to get a handle on the field "Defendant" to fill in a last, first name on this page:
      http://www.hcdistrictclerk.com/Edocs/Public/Search.aspx?Tab=tabCriminal
      I also can't seem to submit the form.   I've tried the code below... stuff may be commented out that I have tested.
       
          _FFOpenUrl("http://www.hcdistrictclerk.com/Edocs/Public/Search.aspx?Tab=tabCriminal")    
          _FFLoadWait()
          $oTextFN = _FSObjGet("ctl00_ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder2_ContentPlaceHolder2_tabSearch_tabCriminal_txtCrimDefendant", "ID")
          
          _FFObj($oTextFN, "value", "Smith, John")    
          $subButton = _FFObjGet("ctl00$ctl00$ctl00$ContentPlaceHolder1$ContentPlaceHolder2$ContentPlaceHolder2$btnSearch", "name")
          _FFClick($subButton)
          _FFLoadWait()
          
      ;    _FFFormSubmit()
      ;    _FFLoadWait()
       
      Any help from the experts on here would be greatly appreciated.  
       
      Jason
       
       
       
       
    • VITSUSA
      By VITSUSA
      I am using window XP in my desktop, so I want to convert basic disk to a dynamic disk, so how it is possible?
    • XaelloNegative
      By XaelloNegative
      Hi,
      I'm currently saving process time stamps of my employer's other employees and saving it in a text document as data storage. However, my employer wants it to be processed in a day to day basis to generate their average process time per day. How can I compare today from yesterday and so on and so forth with the succeeding days? Whats the best approach to this?
      Thank you.
      ~XN~
×