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

    • funkey
      By funkey
      Hello,
      it's quite often, that someone asks how to change the texts of the MsgBox buttons or the InputBox buttons or how to change the position of ta MsgBox. Since years I use CBT hooks for that, but now I made a small UDF out of it for the ease of use. Of course you can build your own GUI or use already existing UDFs to do the same, but I like this way and you can hack (hook) the inbuild InputBox.
       
      HookDlgBox.au3
      #include-once #include <WinAPI.au3> Global Const $tagCBT_CREATEWND = "ptr lpcs;HWND tagCBT_CREATEWND" Global Const $tagCREATESTRUCT = "ptr lpCreateParams;handle hInstance;HWND hMenu;HWND hwndParent;int cy;int cx;int y;int x;LONG style;ptr lpszName;ptr lpszClass;DWORD dwExStyle" Global $g__hProcDlgBox = DllCallbackRegister("__DlgBox_CbtHookProc", "int", "int;int;int") Global $g__TIdDlgBox = _WinAPI_GetCurrentThreadId() Global $g__hHookDlgBox = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($g__hProcDlgBox), 0, $g__TIdDlgBox) Global Const $g__MaxDlgBtns = 5 ; maximum of 5 buttons to rename text Global Const $g__MaxDlgItemId = 11 ; maximun ID of buttons to search is 11 as this is the maximun used in Messagebox Global $g__DlgBoxPosX, $g__DlgBoxPosY, $g__DlgBoxWidth, $g__DlgBoxHeight Global $g__aDlgBoxBtnText[$g__MaxDlgBtns] Global $g__DlgBtnCount = 0 _DlgBox_SetDefaults() OnAutoItExitRegister("__DlgBox_UnregisterHook") Func _DlgBox_SetButtonNames($TxtBtn1 = Default, $TxtBtn2 = Default, $TxtBtn3 = Default, $TxtBtn4 = Default, $TxtBtn5 = Default) $g__aDlgBoxBtnText[0] = $TxtBtn1 $g__aDlgBoxBtnText[1] = $TxtBtn2 $g__aDlgBoxBtnText[2] = $TxtBtn3 $g__aDlgBoxBtnText[3] = $TxtBtn4 $g__aDlgBoxBtnText[4] = $TxtBtn5 $g__DlgBtnCount = @NumParams EndFunc ;==>_DlgBox_SetButtonNames Func _DlgBox_SetPosition($x = Default, $y = Default) ;only for MsgBox, not working and not needed for InputBox $g__DlgBoxPosX = $x $g__DlgBoxPosY = $y EndFunc ;==>_DlgBox_SetPosition Func _DlgBox_SetSize($w = Default, $h = Default) $g__DlgBoxWidth = $w $g__DlgBoxHeight = $h EndFunc ;==>_DlgBox_SetSize Func _DlgBox_SetDefaults() $g__DlgBoxPosX = Default $g__DlgBoxPosY = Default $g__DlgBoxWidth = Default $g__DlgBoxHeight = Default For $i = 0 To UBound($g__aDlgBoxBtnText) - 1 $g__aDlgBoxBtnText[$i] = Default Next EndFunc ;==>_DlgBox_SetDefaults Func __DlgBox_CbtHookProc($nCode, $wParam, $lParam) Local $tcw, $tcs Local $iSearch = 0 Local $ahBtn[$g__DlgBtnCount] If $nCode < 0 Then Return _WinAPI_CallNextHookEx($g__hHookDlgBox, $nCode, $wParam, $lParam) EndIf Switch $nCode Case 3 ;5=HCBT_CREATEWND If _WinAPI_GetClassName(HWnd($wParam)) = "#32770" Then ;Dialoig window class $tcw = DllStructCreate($tagCBT_CREATEWND, $lParam) $tcs = DllStructCreate($tagCREATESTRUCT, DllStructGetData($tcw, "lpcs")) If $g__DlgBoxPosX <> Default Then DllStructSetData($tcs, "x", $g__DlgBoxPosX) If $g__DlgBoxPosY <> Default Then DllStructSetData($tcs, "y", $g__DlgBoxPosY) If $g__DlgBoxWidth <> Default Then DllStructSetData($tcs, "cx", $g__DlgBoxWidth) If $g__DlgBoxHeight <> Default Then DllStructSetData($tcs, "cy", $g__DlgBoxHeight) EndIf Case 5 ;5=HCBT_ACTIVATE For $i = 1 To $g__MaxDlgItemId If IsHWnd(_WinAPI_GetDlgItem($wParam, $i)) Then If $g__aDlgBoxBtnText[$iSearch] <> Default Then _WinAPI_SetDlgItemText($wParam, $i, $g__aDlgBoxBtnText[$iSearch]) $iSearch += 1 If $iSearch >= UBound($ahBtn) Then ExitLoop EndIf Next EndSwitch Return _WinAPI_CallNextHookEx($g__hHookDlgBox, $nCode, $wParam, $lParam) EndFunc ;==>__DlgBox_CbtHookProc Func __DlgBox_UnregisterHook() _WinAPI_UnhookWindowsHookEx($g__hHookDlgBox) DllCallbackFree($g__hProcDlgBox) EndFunc ;==>__DlgBox_UnregisterHook Func _WinAPI_SetDlgItemText($hDlg, $nIDDlgItem, $lpString) Local $aRet = DllCall('user32.dll', "int", "SetDlgItemText", _ "hwnd", $hDlg, _ "int", $nIDDlgItem, _ "str", $lpString) Return $aRet[0] EndFunc ;==>_WinAPI_SetDlgItemText  
      Simple example to see how to use it
      #include "HookDlgBox.au3" _DlgBox_SetButtonNames("1", "two", "3") MsgBox(4, "Test 1", "Custom button texts") _DlgBox_SetPosition(20, 20) MsgBox(66, "Test 2", "Custom position and button texts") _DlgBox_SetButtonNames("Submit", "Don't submit", "Don't know") InputBox("Test 3", "Where were you born?", "Planet Earth") _DlgBox_SetSize(800, 800) InputBox("Test 4", "Where were you born?", "Planet Earth") _DlgBox_SetSize(Default, 800) MsgBox(66, "Test 5", "Strange but working") _DlgBox_SetButtonNames(Default, "Wait", "What?") _DlgBox_SetSize(Default, Default) _DlgBox_SetPosition(500, 500) MsgBox(66, "Test 6", "So far so good!") _DlgBox_SetDefaults() MsgBox(6, "Test 7", "Default position and button texts") Hope you like it.
       
      Best regards
      funkey
      HookDlgBox Example.au3
      HookDlgBox.au3
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      i am working on a application where if the flashing is success i get a window saying "SUCCESS" and if the flashing failed a window saying "FAILED" and i have to automatically identify pass or fail.the problem is both the windows are having the same control ID. how can i differentiate between both windows? so that i can make use of that in script for automation///
       
       
      Thanks
    • comtech80
      By comtech80
      Folks,
      I have an issue I've been trying to solve for a while, I'm trying to add static routes in DHCP via a 121 route rule in Windows 2012 R2 is a brutal manual process and wanted to automate this via AutoIT.
       
      When I use the "ControlGetText" everything displays properly in the MSG box but when I try and use "ControlSetText" or "ControlSend" the values won't display in the input box but the action comes back as successful?
      Anyone able to help me with this? I'm thinking this might be an active window issue but i'm not sure.
      Here is a part of my code.
       
      $hWnd = WinWait("[TITLE:Add a Static Route]","", 10)
      WinActivate($hWnd)
      $Status = ControlSend($hWnd, "", "[CLASS:Edit; INSTANCE:4]", "192"); Does not add 192 to the text box.
      Local $sTextEdit1 = ControlGetText($hWnd, "", "[CLASS:Edit; INSTANCE:1]")
      ConsoleWrite ( "ControlSend Status: " &  $Status & @CRLF); Returns a Value of 1
      ConsoleWrite ( "ControlGetText Value Edit1: " &  $sTextEdit1 & @CRLF);
       
      Please see attachment for more info.

    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys i am working on automating a flashing tool..When flashing is started if there is any error in connection it pops's up a error window...(as shown below)

       whenever this popup appears i need a msgbox to appear saying "error occured" how can i do this?
      Thanks

    • lganta
      By lganta
      Hello!
      I created some scripts for a simple farming bot a few years ago and they rely on ControlSend.
      A year ago I quit that game and then installed Windows 10 (was using windows 7).
      Recently I installed that game and tried running them again and they seem to work (I have some messages displayed on the screen with the state of the bot ), except for the ControlSend part (which obviously is crucial).
      I started debugging the scripts so I created a basic script that makes use of Send. I tested this with Notepad in focus and works just fine and then with my game window in focus and it didn't work (it's supposed to write that text in an input box from the game).
      #include <MsgBoxConstants.au3> Sleep(3000); Send("some text"); MsgBox($MB_OK, "Notification", "Control was sent!");  
      Is there a way for the creators of the game to create some kind of security system against this? Or something happens because I updated to Windows 10?
      Is there something I'm missing?
      Thank you!