Windows Service - Stop Service - Restart Service
Posted: Wed Jan 01, 2020 10:25 pm
Hi,
Happy New Year to everyone.
First Question:
I would like to do some Checks in the Invoke-MyService Function, when the check fail, i would like to Stop the Service.
Is this possible?
This is, what i tried, but this doesn't work.
In the EventViewer => Application I found the Error Message from the THROW, but the Service is still on "Running"
function Invoke-MyService
{
$global:bServiceRunning = $true
while ($global:bRunService)
{
try
{
if($global:bServicePaused -eq $false) #Only act if service is not paused
{
# Check if Configuration File exists
if (-not (Test-Path -Path $XMLReportConfigurationPath))
{
$global:bRunService = $false
throw ("Configuration XML not Found!")
}
Second Question:
Is it possible to restart the Windows Service every 24 hours?
Thanks
Happy New Year to everyone.
First Question:
I would like to do some Checks in the Invoke-MyService Function, when the check fail, i would like to Stop the Service.
Is this possible?
This is, what i tried, but this doesn't work.
In the EventViewer => Application I found the Error Message from the THROW, but the Service is still on "Running"
function Invoke-MyService
{
$global:bServiceRunning = $true
while ($global:bRunService)
{
try
{
if($global:bServicePaused -eq $false) #Only act if service is not paused
{
# Check if Configuration File exists
if (-not (Test-Path -Path $XMLReportConfigurationPath))
{
$global:bRunService = $false
throw ("Configuration XML not Found!")
}
Second Question:
Is it possible to restart the Windows Service every 24 hours?
Thanks