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:
- Create your task via
schtasks.exe /create /tn MyTask ...
- Export your task to XML via
schtasks.exe /query /xml /tn MyTask > MyTask.xml
- Update this XML via XSLT or a search/replace
- Re-import (overwriting the old task) via
schtasks.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