Windows Service not Stopping

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
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.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
lpalacio
Posts: 13
Last visit: Wed Mar 13, 2024 6:42 am

Windows Service not Stopping

Post by lpalacio »

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?
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Windows Service not Stopping

Post by Alexander Riedel »

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.
Alexander Riedel
SAPIEN Technologies, Inc.
User avatar
lpalacio
Posts: 13
Last visit: Wed Mar 13, 2024 6:42 am

Re: Windows Service not Stopping

Post by lpalacio »

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
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Windows Service not Stopping

Post by Alexander Riedel »

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.
User avatar
lpalacio
Posts: 13
Last visit: Wed Mar 13, 2024 6:42 am

Re: Windows Service not Stopping

Post by lpalacio »

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.
  1. while($true){}
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/
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Windows Service not Stopping

Post by Alexander Riedel »

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.
User avatar
lpalacio
Posts: 13
Last visit: Wed Mar 13, 2024 6:42 am

Re: Windows Service not Stopping

Post by lpalacio »

Correct, as far as windows is concerned the service is stopped.
User avatar
lpalacio
Posts: 13
Last visit: Wed Mar 13, 2024 6:42 am

Re: Windows Service not Stopping

Post by lpalacio »

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.
User avatar
Alexander Riedel
Posts: 8478
Last visit: Tue Mar 26, 2024 8:52 am
Answers: 19
Been upvoted: 37 times

Re: Windows Service not Stopping

Post by Alexander Riedel »

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.
Alexander Riedel
SAPIEN Technologies, Inc.
This topic is 6 years and 3 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.