A user of mine is having troubles when scheduling a task from his win2k3 server to a Win7
Everything always works from other servers and for other pc's.
The error he's getting is "The system cannot find the path specified. (Exception from HRESULT: 0x80070003)"
This happens when calling "RegisterTaskDefinition" using the following bit of code:
ts.RootFolder.RegisterTaskDefinition("Rester", tduser, TaskCreation.CreateOrUpdate, Domain + "\\" + User, password, TaskLogonType.Password);
Bit of context(test)
```
Try
{
WindowsImpersonationContext ImpersoToken = Impersonate(User, Domain, password);
if (ImpersoToken != null)
{
using (ImpersoToken)
{
using (TaskService ts = new TaskService(hostname, null, null, null, !IsVistaOrLater))
{
TaskDefinition tduser = ts.NewTask();
bool newVer = (ts.HighestSupportedVersion >= new Version(1, 2));
tduser.Actions.Add(new ExecAction("cmd", "/c set >> " + rootPath + "\\Test.txt", null));
tduser.Settings.DisallowStartIfOnBatteries = false;
tduser.Settings.StopIfGoingOnBatteries = false;
if (newVer)
{
tduser.Principal.RunLevel = TaskRunLevel.Highest; //v2.0
tduser.Settings.AllowDemandStart = true;
}
tduser.RegistrationInfo.Description = "Tester";
try
{
ts.RootFolder.RegisterTaskDefinition("Tester", tduser, TaskCreation.CreateOrUpdate, Domain + "\\" + User, password, TaskLogonType.Password);
ts.GetTask("Tester").Run();
}
catch (Exception ex)
{
//handleException(ex);
}
}
}
RevertToSelf();
}
}
catch (Exception ex)
{
//handleException(ex);
}
```
Everything always works from other servers and for other pc's.
The error he's getting is "The system cannot find the path specified. (Exception from HRESULT: 0x80070003)"
This happens when calling "RegisterTaskDefinition" using the following bit of code:
ts.RootFolder.RegisterTaskDefinition("Rester", tduser, TaskCreation.CreateOrUpdate, Domain + "\\" + User, password, TaskLogonType.Password);
Bit of context(test)
```
Try
{
WindowsImpersonationContext ImpersoToken = Impersonate(User, Domain, password);
if (ImpersoToken != null)
{
using (ImpersoToken)
{
using (TaskService ts = new TaskService(hostname, null, null, null, !IsVistaOrLater))
{
TaskDefinition tduser = ts.NewTask();
bool newVer = (ts.HighestSupportedVersion >= new Version(1, 2));
tduser.Actions.Add(new ExecAction("cmd", "/c set >> " + rootPath + "\\Test.txt", null));
tduser.Settings.DisallowStartIfOnBatteries = false;
tduser.Settings.StopIfGoingOnBatteries = false;
if (newVer)
{
tduser.Principal.RunLevel = TaskRunLevel.Highest; //v2.0
tduser.Settings.AllowDemandStart = true;
}
tduser.RegistrationInfo.Description = "Tester";
try
{
ts.RootFolder.RegisterTaskDefinition("Tester", tduser, TaskCreation.CreateOrUpdate, Domain + "\\" + User, password, TaskLogonType.Password);
ts.GetTask("Tester").Run();
}
catch (Exception ex)
{
//handleException(ex);
}
}
}
RevertToSelf();
}
}
catch (Exception ex)
{
//handleException(ex);
}
```