I have a script which, when ran manually, works just fine. When I configure it to run as a scheduled task though this portion of the script never completes even though task scheduler marks it as successful. I've commented out every other line of the script to isolate this part being the first failure.

The settings for the scheduled task are quite simple. Running the task as a service account which has log on as batch rights, run whether logged on or not and with highest privileges. Trigger is daily at 4am. Action is start a program (powershell) with .\script.ps1 as argument and starting in D:.

Set-Service -Name *service* -StartupType Disabled

When running as a scheduled tasks, your account has very limited permissions to access Windows Service information, much less than running it interactively.

I wrote a bit about this: Accessing the status of Windows services from a scheduled task

You can either run your tasks as an administrator or LocalSystem, or give your service account more permissions to access the service in question.

ProcessHacker is a nice GUI tool that allows you to set permissions on services without using the rather cryptic Security Descriptor Definition Language (SDDL).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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