Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running maintenance plans at night on my SQL Server 2008 database for reorganizing the indexes and shrinking the database. While this plan is running a windows service that I built that queries the DB keeps failing with timeouts.

How can I stop the Windows Service from within the Maintenance Plan?

share|improve this question
up vote 1 down vote accepted

you can use the xp_cmdshell SP to issue a net stop <service_name> then a net start <service_name>

share|improve this answer
Thanks Zypher, I was going this route, but I'm getting a System error 5 has occurred. Access Denied. Do you know in which user context do the Maintenance Plans run as? – Jonas Stawski Jan 8 '10 at 0:59
You might need to set the proxy account, or strait out enable the SP See the remarks section (about halfway down) of my technet link for the howto – Zypher Jan 8 '10 at 1:05
do you know which security rights I should grant the user to be able to execute the net command? Maybe I should open a new question for that – Jonas Stawski Jan 8 '10 at 1:16
You're options are 1) (local | domain) admin or 2) Grant a user permissions by following this KB – Zypher Jan 8 '10 at 1:29
this is very weird. Since I can't get this to work. I added the user running the SQL Server Service as part of the admin group and when I run the xp_cmdshell I still get Access is denied. What could I be doing wrong? – Jonas Stawski Jan 8 '10 at 3:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.