Jump to content

Services


Nunos
 Share

Recommended Posts

The script below I have used for a while now to check a service and restart it if it is not running but it recently began failing to restart the service. Can you advise me if the script is wrong or if there is a better way to do it. The specific place that attempts to restart the service is on line 114.

 

#RequireAdmin
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=C:\Users\booke\Desktop\Dinerware Icons\Icons\FixDinerWareSQL.ico
#AutoIt3Wrapper_Res_Comment=Script to check the Dinerware SQL service and make sure it is running.
#AutoIt3Wrapper_Res_Description=Check for running the Dinerware SQL service.
#AutoIt3Wrapper_Res_Fileversion=1.0.0.8
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Run_Tidy=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include "Services.au3"
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Local $aProcessesNames[2]
$aProcessesNames[0] = "Brain.exe"
$aProcessesNames[1] = "workstation.exe"

; Loop through processes names, calling StopProcesses for each row
For $i = 0 To UBound($aProcessesNames) - 1
    StopProcesses($aProcessesNames[$i])
Next

Func StopProcesses($sProcessName)
    ;Local $sProcessName
    Local $aProcessList = ProcessList($sProcessName)

    For $i = 0 To $aProcessList[0][0]
        ;MsgBox($MB_SYSTEMMODAL, "", $aProcessList[$i][0] & @CRLF & "PID: " & $aProcessList[$i][1])
        ProcessClose($sProcessName)
    Next

EndFunc   ;==>StopProcesses


Local $sServiceName = "MSSQL$DINERWARE" ;--> The name of the Dinerware SQL Service from services.msc
Local $aiExist = _Service_Exists($sServiceName)
Local $aiStatus = _Service_QueryStatus($sServiceName)


If $aiExist = 1 Then ServiceStatus() ;MsgBox(0, "Service Exists", "The Service indeed does EXIST")
If $aiExist = 0 Then _Error_Message_Gui() ;Changed this to the generic error message gui function if you see this it would mean the Dinerware SQL Service isn't there


Func ServiceStatus()
    SplashTextOn("Fix Dinerware SQL Service", "Verifying the SQL services required for Dinerware Brain are running..", -1, -1, -1, -1, "32", "", 24)
    Sleep(5000)
    SplashOff()
    ;MsgBox(0, "Checking", "Checking the status of the service.") ;---> Currently just to let me know the script made it here likely will get replaced with a splash Image

    Select
        Case $aiStatus[1] = $SERVICE_STOPPED ;---> Case for if the service is in a stopped state below tries to restart it and tell you it worked or not
            _Service_Status_GUI()
            ;MsgBox(0, "Result", "The Service start was:  " & ((_Service_Start($sServiceName) = 0) ? "failure" : "successful"))

        Case $aiStatus[1] = $SERVICE_RUNNING ;---> Case for if the service is running and below tries to restart it in case it is hung up
            _Service_Status_GUI()
            ;MsgBox(0, "Result", "The Service restart was:  " & ((_Service_Resume($sServiceName) = 0) ? "failure" : "successful"))

        Case $aiStatus[1] = $SERVICE_START_PENDING ;---> Case for if the service is trying to start not sure what to do here so I am currently calling an error message function I made below.
            _Error_Message_Gui()

        Case $aiStatus[1] = $SERVICE_STOP_PENDING ;---> Case for if the service is trying to stop again not sure what to do here so I am currently calling an error message function I made below.
            _Error_Message_Gui()

        Case $aiStatus[1] = $SERVICE_CONTINUE_PENDING ;---> Case for the service resuming not sure what to do here so I am currently calling an error message function I made below.
            _Error_Message_Gui()

        Case $aiStatus[1] = $SERVICE_PAUSE_PENDING ;---> Case for the service getting ready to pause not sure what to do here so I am currently calling an error message function I made below.
            _Error_Message_Gui()

        Case $aiStatus[1] = $SERVICE_PAUSED ;---> Case for the service in a paused state below attempts to restart and check for success or failure.
            _Service_Status_GUI()
            ;MsgBox(0, "Result", "The Service restart was:  " & ((_Service_Resume($sServiceName) = 0) ? "failure" : "successful"))
    EndSelect
EndFunc   ;==>ServiceStatus

Func _Error_Message_Gui() ;---> A function to show an error message on the screen that the script couldn't sort it so please call IDS

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Fix Dinerware SQL ERROR!", 485, 245, -1, -1)
    GUISetIcon("C:\Users\booke\Documents\Scirpting\AutoIT\In Progress and Researching\DW DB Backup\DW Backup.ico", -1)
    $Pic1 = GUICtrlCreatePic("C:\Users\booke\Documents\Scirpting\AutoIT\In Progress and Researching\Services\115px-Nuvola_apps_error.svg.bmp", 40, 56, 100, 100)
    $Label1 = GUICtrlCreateLabel("We were unable to fix the error!", 152, 75, 337, 80)
    GUICtrlSetFont($Label1, 12)
    $Label2 = GUICtrlCreateLabel("Please contact your Dinerware Dealer,", 152, 95, 337, 20)
    GUICtrlSetFont($Label2, 12)
    $Label3 = GUICtrlCreateLabel("for help.", 152, 115, 337, 40)
    GUICtrlSetFont($Label3, 12)
    Local $idClose = GUICtrlCreateButton("Close", 364, 200, 80, 30)
    GUICtrlSetFont($idClose, 12)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

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

        EndSwitch
    WEnd


EndFunc   ;==>_Error_Message_Gui



Func _Service_Status_GUI() ;---> A function to show a gui with the results of various actions performed on the services with services.au3

    GUICreate("Fix Dinerware SQL", 485, 245, -1, -1)
    GUISetIcon("C:\Users\booke\Documents\Scirpting\AutoIT\In Progress and Researching\DW DB Backup\DW Backup.ico", -1)
    $Pic1 = GUICtrlCreatePic("C:\Users\booke\Documents\Scirpting\AutoIT\In Progress and Researching\Services\1024px-Info_icon_001.jpg", 40, 56, 100, 100)
    $Label1 = GUICtrlCreateLabel("The Service restart was:  " & ((_Service_Resume($sServiceName) = 0) ? "failure" : "successful"), 152, 75, 337, 80)
    GUICtrlSetFont($Label1, 12)
    Local $idClose = GUICtrlCreateButton("Close", 364, 200, 80, 30)
    GUICtrlSetFont($idClose, 12)
    GUISetState(@SW_SHOW)

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

        EndSwitch
    WEnd

EndFunc   ;==>_Service_Status_GUI


Select
    Case FileExists("C:\Program Files (x86)\Basics\Brain.exe")
        RunWait("C:\Program Files (x86)\Basics\Brain.exe") ;---> Start the Basics Version of the Brain Software

    Case FileExists("C:\Program Files (x86)\Dinerware 3.4\Brain.exe")
        RunWait("C:\Program Files (x86)\Dinerware 3.4\Brain.exe") ;---> Start Version 3.4 of the Brain Software

    Case FileExists("C:\Program Files (x86)\Dinerware\Brain.exe")
        RunWait("C:\Program Files (x86)\Dinerware\Brain.exe")

EndSelect

 

Attached are the needed au3's that I believe were authored by engine.

 

Than you in advance for any help getting this to work again. 

SecurityEx.au3

Services.au3

Edited by Nunos
code block
Link to comment
Share on other sites

Sometimes a service may not start until it's dependencies are up.

Not sure if this is the case, or if it's a script issue and i cannot verify atm.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

@careca 

I am not sure if that is the issue or not either. The script was working though at one point in time and recently began not working. I will check a computer later today to see what dependencies are listed for the service and report back. 

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...