Jump to content

Msgbox not Showing when GUI Runs


Recommended Posts

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

@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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
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
 Share

×
×
  • Create New...