Jump to content
Sign in to follow this  
sobert

Stopping Service Before it Starts

Recommended Posts

sobert

Hello,

I have a script that is constantly getting stuck because a Windows service keeps starting and interrupting the script.

I tried using  RunWait(@ComSpec & " /c " & 'net stop CcmExec', "", @SW_HIDE) but then realized that the service has not started yet when I run that command.

Is there a way to stop a service from running before it even starts?

Note: Disabling the service all together is not an option because in the event this script gets hung or fails, that service will remain disabled.

Thanks in advanced.

Edited by sobert

Share this post


Link to post
Share on other sites
spudw2k

I am not aware of a way besides changing the startup. You could attempt to stop the service, set the service startup to manual, run your script and undo (change the startup back to automatic and star the service).  Obviously this runs the same risk as your "Disabling" scenario (script failure and revert revert service).

You could always query the service and wait until it is running, then stop it and continue your script.

Hopefully there isn't another process that will launch the service, otherwise I think your only option is to disable the service.
 

Share this post


Link to post
Share on other sites
JLogan3o13

What are you doing in your script that it is getting hung up by ccmexec? As this is the service for SCCM, unless you're the SCCM admin for your enterprise (in which case you would have the tools to delay startup of this service) I would be curious as to why you're trying to block it's launch?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites
spudw2k

I ran into the same issue in my org.  I didn't script nor go into why it was necessary, but apparently the CCM service interfered with user state migration automation script.
Not especially helpful, and like I said, I don't know the technical reason or limitation involved.  I am just empathizing.

Share this post


Link to post
Share on other sites
JLogan3o13

It was truly a curiosity question; in all my years with SCCM and SMS before it, I never ran into an issue where I had to kill the service. Seems an odd situation; would likely be better to spend the time to find out why ccmexec is causing the problem, rather than killing the service (which can cause problems with the machine heartbeat, etc. etc.).

 

@OP - If you really cannot do it any other way, I would rethink this:

Note: Disabling the service all together is not an option because in the event this script gets hung or fails, that service will remain disabled.

​If you are using proper error checking, your concern for the script hanging or failing should be minimal. I would set the service startup type to disabled, do what you need to do in your script, then set it to enabled and then restart service. Again, not at all my first avenue of choice, but definitely the way I would approach it if I absolutely had no alternative.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×