Jump to content

Stopping Service Before it Starts


Recommended Posts

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
Link to comment
Share on other sites

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.
 

Link to comment
Share on other sites

  • Moderators

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?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • Moderators

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.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...