1

I am trying to create a bat file which when double clicked will create a task in task scheduler from xml file. I need to modify the target location dynamically since the one given in the xml will be different.

So i wrote two commants, first one for creating task form the xml, next one will edit it.

schtasks.exe /Create /XML myxml.xml /tn "mytask" /RU SYSTEM

SchTasks /Change /TN "mytask" /TR "%cd%\start.vbs"

This is working fine, but the second line is asking for user password. Is there any way i can avoid this?

anandhu
  • 686
  • 2
  • 13
  • 40

1 Answers1

0

I came up with this workaround which helped me to bypass that password thing. So solved my issue.

1. Create a power shell script modifyxml.ps1 to modify the target value in XML

$xml = [xml](Get-Content .\myxml.xml)
$path="PATH_TO_UPDATE" // Use proper logic here to get your target path
$xml.Task.Actions.Exec.Command = $path.ToString()
$xml.Save(".\myxml.xml")

2. Now execute this powershell script which will modify the xml, and then create task using it.

Powershell.exe -executionpolicy bypass -File modifyxml.ps1
schtasks.exe /Create /XML myxml.xml /tn "mytask"

Now my task got created with the updated xml which had the correct target path. So i didnt have to change the task later to modify the target location.

anandhu
  • 686
  • 2
  • 13
  • 40