Windows Task Scheduler starts with parameter Auto-modification

Source: Internet
Author: User
Tags schtasks

After the Windows Task Scheduler is established, manual operation can be successful, but the scheduled task will not run successfully, the search network, originally from the parameter is not configured, the English name of this parameter is start-in. It guarantees that the workingdirectory of the Task Scheduler is the path you set, but unfortunately this parameter can only be set manually on Win7 or win2008, so how can I use the command to automatically modify it?

Have tried many ways of netizens, at present, summed up two kinds of feasible methods to:

1 for Windows2012, use PowerShell for parameter setting

Reference:

Specifying "start-in" directory in schtasks command in Windows

Exectype Complex Type

2 for Win7 or Windows2008, you can modify it automatically by modifying the XML method:

First: Create a Task Scheduler with a command for the first time

Then: Export to XML format by command

Again: Modify the XML through the script, adding the start parameter

Finally: Re-import the XML (overwrite) to

Say so much, how to use command implementation, here is one of my test example

The main commands to use are:

  1. Create your task viaschtasks.exe /create /tn MyTask ...
  2. Export your task to XML viaschtasks.exe /query /xml /tn MyTask > MyTask.xml
  3. Update this XML via XSLT or a search/replace
  4. Re-import (overwriting the old task) viaschtasks.exe /create /tn MyTask /xml MyTask.xml /f
::Modify Scheduled Task program, due to Chinese export error, so set the active code page number 437 MS-DOS American Englishchcp437::Start export of Task Scheduler named Smdb_agentSchtasks.exe/query/xml/tn smdb_agent > C:\tmp\SMDB_Agent.XMLGotomodifyagent: Modifyagent::The following modifications are primarily modified XML to add the Run directorySet"dirpath=d:\smdb_agent\etc\ "cd/d%dirpath%. \setupset"str1=^<workingdirectory^>%CD%^<^/workingdirectory^> "for/f"Delims=!"%%i in (' Type c:\tmp\SMDB_Agent.xml ') do (echo%%i>>c:\tmp\smdb_agentnew.xmlecho"%%i" |findstr "Command">nul&&echo%str1%>>c:\tmp\smdb_agentnew.xml) Goto import:: After the modification is complete, you can overwrite the import: Importschtasks.exe/ Create/tn Smdb_agent/xml c:\tmp\smdb_agentnew.xml/f

Reference:

Specifying the running directory for scheduled Tasks using Schtasks.exe

A bat batch file does not execute correctly in Windows Server 2008 under Scheduled tasks

Windows Task Scheduler starts with parameter Auto-modification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.