Alex Rivera | Logout

Specifying the running directory for Scheduled Tasks using schtasks.exe

Asked 2009-01-15T17:52:36.037
51

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.

Edit
Report

2 Answers

9

You can set the start in directory using the following command

The key is the \ in the /tr switch.

SCHTASKS /Create /u username /p pswd /ru "NT AUTHORITY\SYSTEM"
  /rp /sc ONSTART /tn task-name /tr "\"D:\name-of-file-to-run\" "
answered 2009-02-18T17:53:39.460
-1

Use My.Application.Info.DirectoryPath in App without need a XML Setting.

answered 2013-01-28T05:40:13.010

Your Answer