This project has moved. For the latest updates, please go here.

Code works on windows 7 but not on XP

Feb 9, 2012 at 7:41 PM

TaskService ts = new TaskService(server);
Task t = ts.FindTask(task, true);
t.Enabled = enable;

I am trying to enable / disable a task running on a Windows Server 2003 machine from Windows XP. I developed the above code on a Windows 7 box where it works. However when I copy the executable over to Windows XP, the variable "t" on line 3 is null. I have tried forcing version 1, but that did not seem to help.

I also tried:

t = ts.RootFolder.GetTasks(new Regex(task))[0];

Which does not work either. The variable "t" is still null.

Note: Server, task, and enable are variables from the command line arguments.

Feb 9, 2012 at 7:46 PM

Running this code as well produces correct results on Windows 7, and nothing on Windows XP.

foreach (Task item in ts.RootFolder.GetTasks()) {

  Console.WriteLine("\t" + item.Name);
  Console.WriteLine("\t" + item.Path);

Feb 9, 2012 at 8:11 PM

Hmmm interesting. Querying this server with schtasks produces no results either. 

Server name redacted:

C:\>schtasks /s ********** /query
INFO: There are no scheduled tasks present in the system.

Feb 10, 2012 at 12:28 AM

This often is related to the current user account not having permissions to view tasks on the target system. Try specifying user credentials in the other parameters of the TaskService constructor.

Feb 10, 2012 at 1:23 PM

I thought of that as well. However in both cases I am the logged on user. On both the windows 7 box, and the XP box. Also in addition I am an administrator on both of those boxes and the 2003 server. Schtasks and TaskService both work on the Windows 7 box, but not the XP box.

Feb 10, 2012 at 6:48 PM

Logged into the 2003 Server with the same credentials as when you are logged into XP, are you able to run schtasks from the command line and get results? If so, then this has to be permissions problem with either remote access, registry access, or user access. This scenario is one that has worked for myself and many others.

Feb 10, 2012 at 8:10 PM
Edited Feb 10, 2012 at 8:10 PM

Actually I think I figured out what is going on. I ran wireshark and filtered for the 2003 server from the xp box. Both schtasks and this lib went through these same steps running from the XP box:

1) query HKLM\SOFTWARE\Microsoft\SchedulingAgent\TasksFolder
2) query HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\SystemRoot
3) Then it trys to load the files located at \Windows\Tasks\*

However, the tasks on this server are located at \Windows\System32\Tasks\*

However, running from my windows 7 box produced an altogether different wireshark trace. It is using instead of opening the registry and files directly.

Would changing the value of the TasksFolder fix this for the XP box? 

Feb 10, 2012 at 8:23 PM

Well I went ahead and updated that registry entry. I see the tasks coming back in wireshark. However my the library still does not find the task. How odd.

Here is what I see in Wireshark:

  1. SMB Trans2 Request, FIND_FIRST2, Pattern: \Windows\System32\Tasks\*
  2. SMB Trans2 Response, FIND_FIRST2, Files: . .. Microsoft SIP IVR Tester 

The "SIP IVR Tester" is the one I am looking for.

Feb 13, 2012 at 8:30 PM

I gave up, and used PsExec to remotely execute schtasks on the remote server.