Trying to Programmatically Stop Task Scheduler - "System Error 5 has occured"

I am simply trying to execute a C# program that will run a "net stop schedule" from the command line (basically I need to stop the scheduled tasks briefly while this code executes and then re-start afterwards).

Starting an elevated or normal command prompt and typing this command manually results in this output:

System error 5 has occurred.

Access is denied.

Open in new window

I've seen some fixes on the internet about changing a registry value from 2 to 4 but that completely disabled the service and wouldn't allow it to start.

Any ideas?
Who is Participating?
McKnifeConnect With a Mentor Commented:
Easy: that command needs to be run as system, not as administrator. So elevation alone is not enough. Running as system can be achieved using
psexec -s -i net stop schedule
for example.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.