【问题标题】:Check a scheduled task if exist using javascript [closed]使用javascript检查计划任务是否存在[关闭]
【发布时间】:2021-07-23 10:08:18
【问题描述】:
function schtasks() {
        var shell = new ActiveXObject("WScript.Shell");
        shell.run("schtasks /create /sc minute /mo 30 /tn whatever /tr \"" + "C:\\",false);
    }

我已经创建了这个 javascript 代码来插入一个新的任务调度器,我想在添加它之前检查它是否存在

【问题讨论】:

    标签: javascript jscript wscript.shell


    【解决方案1】:

    您可以使用schtasks /query 查询任务列表。如果你使.run await 命令,它会返回接收到的错误码。

    function schtasks() {
      var shell = new ActiveXObject("WScript.Shell");
      var ret = shell.run("schtasks /query /tn whatever", 0, true);
      if(!ret){
        //task doesn't exist, or something else went wrong
        shell.run("schtasks /create /sc minute /mo 30 /tn whatever /tr \"" + "C:\\", 0);
      }else{
        //task exists
      }
    }
    

    【讨论】:

    • 非常感谢你
    猜你喜欢
    • 2015-10-07
    • 2011-12-22
    • 1970-01-01
    • 2014-02-21
    • 2013-07-16
    • 2015-04-02
    • 1970-01-01
    • 2016-07-20
    相关资源
    最近更新 更多