Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying the running directory for Scheduled Tasks using schtasks.exe

I have an application which gets called by a scheduled task. It moved from Windows Server 2003 to Windows Server 2008. On 2003, the app ran in the directory where the executable was located. On 2008 Environment.CurrentDirectory (C#) reports that it's running in C:\Windows\System32. How do I set the running directory? I'm using schtasks.exe for command-line deployment.

UPD: Through the interface, it seems to be the "Start in (optional)" field on the action edit screen.

UPD: Looks like using the XML file may help, but I'm looking to do without it.

like image 315
Eugene Katz Avatar asked Jan 15 '09 17:01

Eugene Katz


People also ask

Where is Schtasks located?

The schtasks.exe file is located in the C:\Windows\System32 folder.

What is working directory in Task Scheduler?

The default working directory for a scheduled task running as the Local System account is. %Windir%\System32\


2 Answers

Just wanted to add details that are valid for Windows Server 2008 and 2012. As many people can understand screen shots better here is a screen shot:
enter image description here

To sum it up. When you create the action for your scheduled task you have the option to set the "Start in (optional)" field (rounded in red on the screen shot). This will be the directory from where your process is triggered.

Hope this helps!

like image 159
Angel Naydenov Avatar answered Sep 21 '22 08:09

Angel Naydenov


I recently came across the same issue. The way I resolved it was to add the /V1 switch to the schtasks command.

/V1 creates a pre-vista compatible scheduled task and automatically populates the Start In directory.

like image 24
matt.franklin Avatar answered Sep 18 '22 08:09

matt.franklin