Alex Rivera | Logout

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

Asked 2009-06-19T21:06:03.547
27

I realize that this question is "answered" at the following thread: Specifying the running directory for Scheduled Tasks using schtasks.exe

However, I'm still having trouble understanding the answer and seeing exactly what the result would look like for my situation.

My schtasks command looks like this:

Schtasks /Create /TR "C:\Program Files\Java\jre6\bin\javaw.exe main.MoveFile input.txt" /SC WEEKLY /TN mytask

I want to specify the start in directory of "C:\My Library". Putting a "\" before the tr section fills in a start-in directory of "C:\Program Files\Java\jre6\bin".

I've messed around with it a lot, but I just can't seem to make it work.

Edit
Report

1 Answer

3

As you note, the trick of using the extra quotes in the /TR parameter only allows you to use the same directory as where the executable resides. If you want to specify a different working directory, you should use the /XML option and specify an XML file that lists the working directory. The command would be something like this:

SchTasks /Create /TN "Foo" /XML task.xml

The XML file would look something like this:

<?xml version="1.0" ?>
<Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
    <RegistrationInfo>
        <Date>2006-05-02T13:21:17</Date>
        <Author>AuthorName</Author>
        <Version>1.0.0</Version>
        <Description>Call MoveFile</Description>
    </RegistrationInfo>
    <Triggers>
        <CalendarTrigger>
            <StartBoundary>2011-11-02T00:00:00</StartBoundary>
            <ScheduleByDay>
                <DaysInterval>1</DaysInterval>
            </ScheduleByDay>
        </CalendarTrigger>
    </Triggers>
    <Principals>
        <Principal>
            <UserId>Administrator</UserId>
            <LogonType>InteractiveToken</LogonType>
        </Principal>
    </Principals>
    <Settings>
        <Enabled>true</Enabled>
        <AllowStartOnDemand>true</AllowStartOnDemand>
        <AllowHardTerminate>true</AllowHardTerminate>
    </Settings>
    <Actions>
        <Exec>
            <Command>C:\Program Files\Java\jre6\bin\javaw.exe</Command>
            <Arguments>main.MoveFile input.txt</Arguments>
            <WorkingDirectory>C:\My Library</WorkingDirectory>
        </Exec>
    </Actions>
</Task>

There's more information about the XML schema here: answered 2011-11-02T23:48:52.707

Your Answer