To help you better we need some information from you.
*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***
Product, version and build:
PowerShell Studio 2017 v5.4.145 x64
Operating system:
Windows 10 1703 x64
*** Please add details and screenshots as needed below. ***
When compiling code as a Windows Service and installing the service. Going into the Windows Service Manager and stopping the service does not kill the executable. Is this an issue of the compilation engine or an issue that I need to address on my code?
Windows Service not Stopping
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
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 LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Windows Service not Stopping
The service is designed to kill the currently running script on a stop request. Now, depending on what your script does internally that may still keep the process locked and preventing it from terminating.
Without knowing what your script does in detail, that is very hard to answer.
Without knowing what your script does in detail, that is very hard to answer.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Windows Service not Stopping
Do I need to add code to interact with the OnStop method in order for the executable to stop?
https://msdn.microsoft.com/en-us/librar ... .110).aspx
https://msdn.microsoft.com/en-us/librar ... .110).aspx
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Windows Service not Stopping
Nope. Not necessary in this version. Your script runs in its own thread. The thread gets killed in the stop request. But if you load types/modules etc that create their own thread they may be left hanging and lock the process. Which is why I would need to know what it is you do in your service.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Windows Service not Stopping
I created an empty executable with only a blank loop thinking that something on my code was causing the issue and even this wouldn't kill the running executable when stopping the service on windows.
I even tried it with the solitaire killer in the blog example below and that didn't stop either.
https://www.sapien.com/blog/2017/07/12/ ... owershell/
- while($true){}
https://www.sapien.com/blog/2017/07/12/ ... owershell/
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Windows Service not Stopping
That's kinda weird. I will see what I can find out. Does the service show as stopped in the service panel?
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.
Re: Windows Service not Stopping
Actually I just did some more testing and Windows is complaining that the service is not responding to the stop command. Not sure if that makes a difference.
- Alexander Riedel
- Posts: 8479
- Last visit: Thu Mar 28, 2024 9:29 am
- Been upvoted: 37 times
Re: Windows Service not Stopping
Due to the underlying .NET framework, a process can take between 5 - 30 seconds, depending on machine speed and load, to terminate after the service was stopped.
According to Microsoft this is a normal behavior. We are exploring options to make this go faster since this may impede your ability to start a service again before the process has actually terminated.
According to Microsoft this is a normal behavior. We are exploring options to make this go faster since this may impede your ability to start a service again before the process has actually terminated.
Alexander Riedel
SAPIEN Technologies, Inc.
SAPIEN Technologies, Inc.