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. oracle 中INSTR 函数和SUBSTR函数的使用

    INSTR (源字符串, 目标字符串, 起始位置, 匹配序号) 在Oracle/PLSQL中,instr函数返回要截取的字符串在源字符串中的位置.只检索一次,就是说从字符的开始 到字符的结尾就结束. ...

  2. Qt Delgate的使用 简单说明

    (一) Qt Model/View 的简单说明 .预定义模型 (二)使用预定义模型 QstringListModel例子 (三)使用预定义模型QDirModel的例子 (四)Qt实现自定义模型基于QA ...

  3. DOS 获取硬盘序列号

    DOS命令行操作: 使用diskpart命令,Win+R键运行cmd,进入命令行界面:       1.diskpart       2.list disk 查看有几块硬盘       3.selec ...

  4. 订阅发布模式eventEmiter

    // 订阅发布模式 class EventEmitter { constructor() { this._events = {}; } on(name, callback) { if (this._e ...

  5. LC 641. Design Circular Deque

    Design your implementation of the circular double-ended queue (deque). Your implementation should su ...

  6. JAVA RMI分布式原理和应用

    RMI(Remote Method Invocation)是JAVA早期版本(JDK 1.1)提供的分布式应用解决方案,它作为重要的API被广泛的应用在EJB中.随着互联网应用的发展,分布式处理任务也 ...

  7. Django之contenttypes组件

    目录 一. 介绍 二. 应用场景 1. 表结构设计的演变 2. GenericForeignKey和GenericRelation 3. 测试 一. 介绍 Django包含一个contenttypes ...

  8. 饿了么这样跳过Redis Cluster遇到的“坑”

    内容来源:2017 年 8 月 12 日,饿了么高级Python工程师黄光星在“CRUG 2017北京活动”进行<Redis Cluster运维方案>演讲分享.IT 大咖说(微信id:it ...

  9. 爬虫——简单处理js中嵌入的json数据

    看了群里一个人提问道https://www.amazon.com/,商品分类那里无法用xpath拿得到列表.遂对其研究. 通过抓包工具可以得知,原始数据存在于js代码中,我的方式是手动解析js,从里面 ...

  10. intellij idea for mac 2018 破解版

    下载地址:https://pan.baidu.com/s/1DNo3CvkI7EMy6Mt0hdzTpg 1.在本站下载好mac文件包,打开dmg镜像文件,将“IntelliJ IDEA”拖入到“Ap ...