Jump to content

Recommended Posts

Posted

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.

  • Administrators
Posted

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 = "[email protected]"
$EmailTo = "[email protected]"
$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("[email protected]", "your-email-password")
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

Step 2: Set Up a Scheduled Task

  1. Open Task Scheduler and create a new task.
  2. General Tab: Name your task and set it to run whether the user is logged on or not.
  3. 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
  4. 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"
  5. 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.

Posted

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.

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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