Luciano Grosso 0 Posted 15 hours ago Share Posted 15 hours ago Good morning, how are you? Is there a way to generate a notification via email when a Windows service is stopped or started? Thank you very much. Regards. Quote Link to comment Share on other sites More sharing options...
Administrators Marcos 5,382 Posted 15 hours ago Administrators Share Posted 15 hours ago le this is beyond the scope of this forum, I've found the following: Step 1: Create a PowerShell Script First, you need a PowerShell script that sends an email. Here’s a basic example: $filter = "*[System[EventID=7036] and EventData[Data='YourServiceName']]" $A = Get-WinEvent -LogName System -MaxEvents 1 -FilterXPath $filter $Message = $A.Message $EventID = $A.Id $MachineName = $A.MachineName $Source = $A.ProviderName $EmailFrom = "your-email@example.com" $EmailTo = "recipient-email@example.com" $Subject = "Alert from $MachineName" $Body = "EventID: $EventID`nSource: $Source`nMachineName: $MachineName `n$Message" $SMTPServer = "smtp.your-email-provider.com" $SMTPClient = New-Object Net.Mail.SmtpClient($SMTPServer, 587) $SMTPClient.EnableSsl = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("your-email@example.com", "your-email-password") $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body) Step 2: Set Up a Scheduled Task Open Task Scheduler and create a new task. General Tab: Name your task and set it to run whether the user is logged on or not. Triggers Tab: Create a new trigger that starts the task on an event. Use the following settings: Log: System Source: Service Control Manager Event ID: 7036 Actions Tab: Create a new action to start a program. Set the program/script to powershell.exe and add the following arguments: -File "C:\Path\To\Your\Script.ps1" Conditions and Settings Tabs: Adjust these as needed, but the defaults should work fine. Step 3: Test Your Setup Manually start and stop the service to ensure the script runs and you receive the email notifications. This setup will send an email whenever the specified service starts or stop. If you need more detailed filtering or customization, you can modify the PowerShell script and the event filter accordingly. Quote Link to comment Share on other sites More sharing options...
Luciano Grosso 0 Posted 14 hours ago Author Share Posted 14 hours ago I thought it was possible with ESET Inspect, I have created email notifications based on the rules, but I can't find a way to do it with a Windows service. Thanks. Regards. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.