pranaynanda

Msgbox not Showing when GUI Runs

10 posts in this topic

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



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

 

1 person likes this

Share this post


Link to post
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 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - 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

#4 ·  Posted (edited)

@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

I'll just leave this here.

 

 

Share this post


Link to post
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.

Share this post


Link to post
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

 

1 person likes this

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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?

Share this post


Link to post
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.

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

    • Nareshm
      By Nareshm
      I have autoit script like this :
      winActivate ("BillReceipt") ControlClick ( "BillReceipt", "", "[NAME:winviewer]", "right") Send ( "{ENTER}") WinWait ("Print") ControlClick ("Print", "", "[CLASS:Button; INSTANCE:13]") Winwait ("Save As") WinActivate ("Save As") Send ("{TAB 5} {Backspace} ^v {Enter}") I need Saved successfully msgbox with file name as i saved like Filename.extension (Example = test.pdf is saved successfull)

      Please Help
    • nacerbaaziz
      By nacerbaaziz
      Hi dear
      I have a question
      about the display language of the system
      How can I get the current display language and how can I change it by autoit
      Of course, if this is possible
      Greetings to all and hope you help me
    • breakbadsp
      By breakbadsp
      AutoIT AU3info doeas not detect all gui objects uniquely for .NET GUIs developed in C#.
      this is not working now i am using COM windows approach for this, But its very difficult.
      Please let me know if anyone has done it before.
    • Verssuss
      By Verssuss
      hi guys i want avoid to multiple MsgBox by hold Hotkey "]" in my script
       
      #include <GuiConstantsEx.au3> #include <Windowsconstants.au3> #include <SendMessage.au3> #include <WinAPI.au3> ;~ HotKeySet("{[}", "_boxminus") HotKeySet("{]}", "_boxplus") HotKeySet("{ESC}", "On_Exit") $hGUI = GUICreate("", 100, 100, -1, -1, $WS_POPUP, BitOr($WS_EX_LAYERED, $WS_EX_COMPOSITED, $WS_EX_TOPMOST)) GUISetBkColor(0x00FF00) GuiCtrlCreateLabel("", 3, 3, 94, 94) GUICtrlSetBkColor(-1, 0xABCDEF) GUICtrlSetResizing(-1, $GUI_DOCKBORDERS) GUISetState() _WinAPI_SetLayeredWindowAttributes($hGui, 0xABCDEF) $box_range = 100 While 1 $pos = MouseGetPos() WinMove($hGUI, "", $pos[0] - ($box_range / 2), $pos[1] - ($box_range / 2), $box_range, $box_range) WEnd ;~ Func _boxminus() ;~ If $box_range >= 30 Then $box_range = $box_range - 10 ;~ If $box_range < 30 Then $box_range = $box_range - 1 ;~ EndFunc Func _boxplus() If $box_range < 200 Then $box_range = $box_range + 10 Else MsgBox(0,"ERROR", "Maximum size already exist") EndIf EndFunc Func On_Exit() Exit EndFunc i wish after i get first MsgBox another gonna replaced with first one or just cancel in and apeear again
      how can i make it right ???
    • AnonymousX
      By AnonymousX
      Hello,
      I'm trying to make it so that when a message box pops up that the GUI will be unresponsive until that message box has been closed. From reading through the help the closest thing I can find is the WinWaitClose function, however this doesn't work fully as desired. If user tries to click on GUI the actions are more just waiting for the message box to close, so that once it closes everything happens at once. I want it so that the GUI is completely unusable until message box is closed. 
       
      Below is test code to demonstrate the problem and help explain what I want. Any advice on this?
       
      #include <GUIConstantsEx.au3> Example() Func Example() ; Create a GUI with various controls. Local $hGUI = GUICreate("Example") Local $idOK = GUICtrlCreateButton("OK", 310, 370, 85, 25) local $but = GUICtrlCreateButton("Hello", 150,150,85,25) ; Display the GUI. GUISetState(@SW_SHOW, $hGUI) MsgBox( 262144,"Message","Try hitting the hello button several times,without closing this window. Now close this window and see how script wasn't restricted it just was waiting and storing the instructions") WinWaitClose("Message") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE, $idOK Exit case $but MsgBox(0,"","Hello") EndSwitch WEnd ; Delete the previous GUI and all controls. GUIDelete($hGUI) EndFunc ;==>Example