Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 10/02/2024 in all areas

  1. Here : #RequireAdmin #include <GUIConstants.au3> #include <Array.au3> Global $oHandler = ObjEvent("AutoIt.Error", WMIerror) Main() Func Main() Local $hGUI = GUICreate("Service") Local $idServ = GUICtrlCreateCombo("", 10, 10, 250, 25) Local $idActiv = GUICtrlCreateButton("Start/Stop", 30, 50) GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlSetData($idServ, _ArrayToString(GetList())) GUISetState() While True Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $idServ If Not GUICtrlRead($idServ) Then GUICtrlSetData($idActiv, "Start/Stop") GUICtrlSetState($idActiv, $GUI_DISABLE) Else GUICtrlSetData($idActiv, IsStarted(GUICtrlRead($idServ)) ? "Stop" : "Start") GUICtrlSetState($idActiv, $GUI_ENABLE) EndIf Case $idActiv SetState(GUICtrlRead($idServ), GUICtrlRead($idActiv)) If @error Then MsgBox($MB_OK, "Error", "Unable to change state") GUICtrlSetData($idActiv, IsStarted(GUICtrlRead($idServ)) ? "Stop" : "Start") EndSwitch WEnd EndFunc ;==>Main Func GetList() Local $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $oList = $oWMIService.ExecQuery('SELECT name, started FROM Win32_Service') Local $aServ[$oList.count], $i = 0 For $oServ In $oList $aServ[$i] = $oServ.name $i += 1 Next Return $aServ EndFunc ;==>GetList Func IsStarted($sName) Local $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $oService = $oWMIService.Get("Win32_Service.Name='" & $sName & "'") Return $oService.Started EndFunc ;==>IsStarted Func SetState($sName, $sState) Local $oWMIService = ObjGet("winmgmts:\\" & @ComputerName & "\root\CIMV2") Local $oService = $oWMIService.Get("Win32_Service.Name='" & $sName & "'") If $sState = "Start" Then $oService.StartService() Else $oService.StopService() EndIf If @error Then Return SetError(1) EndFunc ;==>SetState Func WMIerror($oError) EndFunc
    1 point
×
×
  • Create New...