Step 1: Check File/Folder Permissions

The first step to fixing this issue is ensuring that the account you are using to run the script in Task Scheduler has Full Control permissions on the folder containing the script, the script itself, and any folders/files that the script touches when it runs.

For example, I created the following batch script below:

set folder="C:\test"
cd /d %folder%
for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)

I saved the .BAT file to my Documents folder. The path is C:\Users\username\Documents. I went to C:\Users\username, right-clicked on the Documents folder, and clicked on Properties. Then I clicked on the Security tab.

 

As you can see, the user account Aseem has been explicitly added and given the Full Control permission.  Now you have to do the same thing for the folder that contains the script and for the script itself. Don’t just assume that if you give permissions to the folder containing the script, you’re good to go, because you’re not. Lastly, set permissions on any files and folders that the script will interact with.

In my case, I had to go to C:\test, right-click on that folder and add my user account there with Full Control permissions. It’s kind of annoying that you have to do this, but it’s the only way to get the script to run.

Note: The account that is being used to run the script has to be part of the local Administrators group on the computer. In my case, the Aseem account is an administrator account and therefore part of the local Administrators group. 

Step 2: Check Task Scheduler Settings

Now let’s go to Task Scheduler and change the appropriate settings there. Open Task Scheduler and find your task under the Active Tasks section. They should be listed out in alphabetical order.

Double-click on it and it’ll open the task by itself in the same window. In order to edit the task, you’ll have to right-click on it and choose Properties.

There are several tabs and a couple of things have to checked and changed here. Firstly, on the General tab, you need to check the user account that is being used to run the task. In my case, it’s the Aseem account, which I had given permissions to earlier on the file system and which is part of the Administrators group on the computer.

Next, you have to choose the Run whether user is logged on or not option and choose Windows Vista, Windows Server 2008 in the Configure for box.

On the Actions tab, you have to select the script, click on Edit and then add in the path to the folder containing the script in the Start in (optional) box. This may seem unnecessary, but it’s not. In my case, I put in C:\Users\Aseem\Documents\ in the box.

Now click on OK to save the settings. When you do this, a dialog may appear where you have to enter the password for the user account that will run the task. This brings up another requirement. You can’t use an account that doesn’t have a password. The user account has to have a password in order for the task to run.

Lastly, you should run the task manually once in Task Scheduler to make sure it runs. If it runs fine manually after you changed all the settings, then it should run when it’s supposed to be triggered. In my case, it was supposed to happen on startup and after I made the changes, everything worked fine.

Note that if your script is accessing different computers in a domain when run, you should try to use the domain administrator account to run the task. This will ensure the account has enough permissions to access the remote computers.

Another item to note is if your script accesses resources on a network share. If your script is using letters to access the network, it may not run. For example, instead of using F:\data\, you should use \\machinename\share_name\data\ in the script. If you still can’t get your script to run, post a comment here and I’ll try to help. Enjoy!

Fix Scheduled Task Won’t Run for .BAT File的更多相关文章

  1. How to Create a Cron Job (Scheduled Task) for Your Website or Blog

    How to Create a Cron Job (Scheduled Task) for Your Website or Blog by Christopher Heng, thesitewizar ...

  2. 【java异常】定时任务异常ERROR 20604 --- [ scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unexpected error occurred in scheduled task

    2019-11-20 13:20:00.006 ERROR 20604 --- [ scheduling-1] o.s.s.s.TaskUtils$LoggingErrorHandler : Unex ...

  3. failed to create pid file /var/run/rsyncd.pid: File exists报错

    [root@pcidata-jenkins ansible_playbooks]# ps aux|grep rsyncroot      1799  0.0  0.0 114652   480 ?   ...

  4. How to run a batch file each time the computer loads Windows

    https://www.computerhope.com/issues/ch000322.htm#:~:text=Press Start%2C type Run%2C and press Enter. ...

  5. 【java异常】Unexpected error occurred in scheduled task. java.lang.StackOverflowError: null

    可能是栈溢出(StackOverFlow) 背景:我用定时器new东西 原因:频率太快了好像!

  6. Gradle Goodness: Rename Ant Task Names When Importing Ant Build File

    Migrating from Ant to Gradle is very easy with the importBuild method from AntBuilder. We only have ...

  7. bat file handling, main: echo type *.txt >> />

    echo.@.call.pause.rem(小技巧:用::代替rem)是批处理文件最常用的几个命令 echo 表示显示此命令后的字符  echo off 表示在此语句后所有运行的命令都不显示命令行本身 ...

  8. win10家庭版,双击bat文件无法运行(double click bat file does not execute)

    win10家庭版,双击bat文件无法运行,弹出文件打开方式选择框. 在网上搜索处理办法,试了以下方法1-5都没有成功,用方法6规避. 方法1:打开一个驱动器,点“工具-文件夹选项→文件类型→新建→扩展 ...

  9. linux bash shell run ros launch file and multi_node

    #!/bin/bash #source /opt/ros/melodic/setup.bash #source /home/pi/catkin_ws/devel/setup.bash #ROS_PAC ...

随机推荐

  1. LeetCode 20. 有效的括号(Valid Parentheses )

    题目描述 给定一个只包括 '(',')','{','}','[',']' 的字符串,判断字符串是否有效. 有效字符串需满足: 左括号必须用相同类型的右括号闭合. 左括号必须以正确的顺序闭合. 注意空字 ...

  2. Flume-日志聚合

    Flume-1 监控文件 /tmp/tomcat.log. Flume-2 监控某一个端口的数据流. Flume-1 与 Flume-2 将数据发送给 Flume-3,Flume-3 将最终数据打印到 ...

  3. docker安装并设置开机启动(CentOS7/8)

    CentOS7.2 docker分为CE和EE版本,EE版本收费,一般我们使用CE版本就满足要求了 docker安装及启动 docker安装很简单,直接使用如下命令安装即可,安装后的docker版本即 ...

  4. mp3收藏

    [程序员一个]一人饮酒醉 https://kg2.qq.com/node/play?s=lW1J2-lrkrR3klvD&shareuid=619598862d2a31893d&top ...

  5. 同源策略和Ajax跨域访问

    1. 什么是同源策略 理解跨域首先必须要了解同源策略.同源策略是浏览器上为安全性考虑实施的非常重要的安全策略.    何谓同源:        URL由协议.域名.端口和路径组成,如果两个URL的协议 ...

  6. vue如何动态绑定v-model

    如图所示有三个字段要从弹出的输入框取值点击字段会弹出上面的弹窗,输入input会响应变化,比如点击身高,弹出输入框,输入值后身高后面会跟着一个同样的值点击体重,弹出输入框,输入值后体重后面会跟着一个同 ...

  7. Android跨进程通信AIDL服务

    服务(Service)是android系统中非常重要的组件.Service可以脱离应用程序运行.也就是说,应用程序只起到一个启动Service的作用.一但Service被启动,就算应用程序关闭,Ser ...

  8. python安装gmpy2模块时出现错误的解决

    接下来表演的是安装Python模块gmpy2 此模块用来进行高精度计算的模块,个人根据需求常用来进行rsa加密算法的计算 作为一个资质浅淡的ubuntu玩家,这些知识当然是在网上搜索得到的,不过网上的 ...

  9. easyU之tabs选项卡

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...

  10. C# 批处理制作静默安装程序包

    使用批处理+WinRAR制作静默安装程序包 @echo 安装完窗口会自动关闭!!! @echo off start /wait Lync.exe /Install /Silent start /wai ...