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
Windows Service - Stop Service - Restart Service
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
-
- Posts: 5
- Last visit: Mon Nov 30, 2020 10:10 pm
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Windows Service - Stop Service - Restart Service
Setting the bRunService variable would only stop the script, but not the outer service layer.
Use
Stop-Service -Name "<Your Service>"
As for the second question, schedule a script to run every 24 hours, check if the service is running, if not, start it with Start-Service otherwise stop it, then start it again.
Use
Stop-Service -Name "<Your Service>"
As for the second question, schedule a script to run every 24 hours, check if the service is running, if not, start it with Start-Service otherwise stop it, then start it again.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
-
- Posts: 5
- Last visit: Mon Nov 30, 2020 10:10 pm
Re: Windows Service - Stop Service - Restart Service
Hi,
thanks for your Answer. This make sense.
Is it possible to show a Messagebox if the Service failed to start?
Thanks
Regards
Daniel
thanks for your Answer. This make sense.
Is it possible to show a Messagebox if the Service failed to start?
Thanks
Regards
Daniel
-
- Posts: 5
- Last visit: Mon Nov 30, 2020 10:10 pm
Re: Windows Service - Stop Service - Restart Service
Thank you for the informations. There is already a message box for services if they cannot start.
Please see the Image.
http://social.technet.microsoft.com/For ... ile/438184
I would like to do a few PreChecks, and if they were unsuccessful,
I would like to display such a messagebox.
Regards
Daniel
Please see the Image.
http://social.technet.microsoft.com/For ... ile/438184
I would like to do a few PreChecks, and if they were unsuccessful,
I would like to display such a messagebox.
Regards
Daniel
Re: Windows Service - Stop Service - Restart Service
That message box is produced by the system and is not part of the service. Think about it, iIf a service can't start how can it display anything. A process can only display output if it can run.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Windows Service - Stop Service - Restart Service
Create an external tool that does your pre-checks, starts the service if successful, displays a message if not.
Such a tool would run in a user context and can display messages etc.
Such a tool would run in a user context and can display messages etc.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
-
- Posts: 5
- Last visit: Mon Nov 30, 2020 10:10 pm