none
List of all Scheduled Tasks that have ran? RRS feed

  • Question

  • Hello,
    Thanks for reading my post, any help is appreciated.  I need to be able to see a remote server and all the jobs under 'scheduled tasks' that have ran. Is there a way this can be done?  Reading from a remote server is optional, but it would be nice for testing purposes.  I tried invoking the following with no luck: 

    Process

    [] processes = Process.GetProcessesByName(Calculator);


    As an example, I created a scheduled task on my local machine which ran (it starts the Microsoft Calculator).  However, the processes is empty? Why didn't the calculator show up in the processes arrray?

    Thanks in advance for your help,
    -sasims

    • Edited by Sasims Monday, September 14, 2009 11:50 PM
    Monday, September 14, 2009 10:29 PM

Answers

  • Hello Sasims,


    There are two kinds of Scheduled Task in the system,
    1.Created via WMI or AT.exe utility
    2.Created via ControlPanel's Scheduled Task Wizard.

    They are using different technologies to store and perform the scheduled task so that WMI can only iterate and operate against on Scheduled Tasks created by WMI or AT.exe command.

    If you want to iterate through system scheduled task, you need to use Task Scheduler API. It is  native COM API so you have to use COM Interop to access it.

    Here are official documenations as well as a wrapper class from MVP site,
    http://msdn.microsoft.com/en-us/library/aa383614(VS.85).aspx
    http://msdn.microsoft.com/en-us/library/aa446881(VS.85).aspx

    http://www.mvps.org/emorcillo/en/code/shell/tasksched.shtml

     

    Ji Zhou

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Tuesday, September 15, 2009 7:01 AM
    Moderator
  • I believe Sasims is saying that the scheduled job is called calculator.

    Sasims, The Process class is for look at actual running processes (applications) and not scheduled task (so process will only give you information about the calculator while the executable is running). 
    In order to look at scheduled task you need to use WMI. It can also be used to look at remote server and the status of scheduled jobs on those servers.

    The following code sample shows you how to get some more info using wmi:

    				//if you are connecting to the local machine, the servername should be "."
    				ManagementPath mp = new ManagementPath(@"\\"+ serverName+ @"\root\cimv2:Win32_ScheduledJob");
    
    				ManagementClass mc = new ManagementClass(mp);
    				obj = mc.GetInstances();
    			
    				foreach(ManagementObject o in obj)
    				{
    					//listBox1.Items.Add( o["Name"]);
    					if(o["Name"]=="Caclulator")
    					{
    						MessageBox.Show("Job status: " +o["Status"]);
    					}
    				}
    


    Hope this helps.


    • Marked as answer by Sasims Tuesday, September 15, 2009 12:56 AM
    • Unmarked as answer by Sasims Tuesday, September 15, 2009 1:59 AM
    • Proposed as answer by Ji.ZhouModerator Tuesday, September 15, 2009 7:01 AM
    • Marked as answer by Ji.ZhouModerator Friday, September 18, 2009 4:00 AM
    Tuesday, September 15, 2009 12:44 AM

All replies

  • What is "Calculator"?  Its process name is calc.exe

    Hans Passant.
    • Proposed as answer by insigniya Monday, September 14, 2009 10:35 PM
    Monday, September 14, 2009 10:32 PM
    Moderator
  • It's the calculator under Accessories.  Yes, it's the "C:\WINDOWS\system32\calc.exe".  When I created the task using the Scheduled Task Wizard, I just selected the Calculator icon from the list of programs.  I'm just created a task as a test?  I had expected the calculator to show up as a Process.
    Monday, September 14, 2009 11:49 PM
  • You didn't answer my question, what is the "Calculator" variable set to?
    Hans Passant.
    Tuesday, September 15, 2009 12:01 AM
    Moderator
  • Is this what you're asking for?

    Task Tab -  Run:  C:\WINDOWS\system32\calc.exe
    Schedule - Schedule Task: Daily; Start Time: 4:59 PM; Schedule Task Daily = 1
    Setting - default (no change)
    Security - default (no change)

    This runs fine, no problems.

    Tuesday, September 15, 2009 12:09 AM
  • I believe Sasims is saying that the scheduled job is called calculator.

    Sasims, The Process class is for look at actual running processes (applications) and not scheduled task (so process will only give you information about the calculator while the executable is running). 
    In order to look at scheduled task you need to use WMI. It can also be used to look at remote server and the status of scheduled jobs on those servers.

    The following code sample shows you how to get some more info using wmi:

    				//if you are connecting to the local machine, the servername should be "."
    				ManagementPath mp = new ManagementPath(@"\\"+ serverName+ @"\root\cimv2:Win32_ScheduledJob");
    
    				ManagementClass mc = new ManagementClass(mp);
    				obj = mc.GetInstances();
    			
    				foreach(ManagementObject o in obj)
    				{
    					//listBox1.Items.Add( o["Name"]);
    					if(o["Name"]=="Caclulator")
    					{
    						MessageBox.Show("Job status: " +o["Status"]);
    					}
    				}
    


    Hope this helps.


    • Marked as answer by Sasims Tuesday, September 15, 2009 12:56 AM
    • Unmarked as answer by Sasims Tuesday, September 15, 2009 1:59 AM
    • Proposed as answer by Ji.ZhouModerator Tuesday, September 15, 2009 7:01 AM
    • Marked as answer by Ji.ZhouModerator Friday, September 18, 2009 4:00 AM
    Tuesday, September 15, 2009 12:44 AM
  • Thanks Ali A G, and the code sample is also appreciated!  Yes, you are correct, I called the scheduled job a "calculator".  :)  I guess that caused some confusion...sorry.

    This is a lot of help!

    Have a great evening!
    -sasims

    Tuesday, September 15, 2009 1:02 AM
  • Hello again,
    I tried using the code example which unfortunately resulted in nothing?  I created the Calculator using the Scheduled Task Wizard.  I search the internet and found several posts stating that using WMI does not recognize scheduled Tasks if it was created using the "Scheduled Task Wizard".  I've been searching the internet for an alternative, however I'm not finding anything.  Surely, Microsoft has a solution for this?

    -sasims 

    Tuesday, September 15, 2009 2:04 AM
  • Hello Sasims,


    There are two kinds of Scheduled Task in the system,
    1.Created via WMI or AT.exe utility
    2.Created via ControlPanel's Scheduled Task Wizard.

    They are using different technologies to store and perform the scheduled task so that WMI can only iterate and operate against on Scheduled Tasks created by WMI or AT.exe command.

    If you want to iterate through system scheduled task, you need to use Task Scheduler API. It is  native COM API so you have to use COM Interop to access it.

    Here are official documenations as well as a wrapper class from MVP site,
    http://msdn.microsoft.com/en-us/library/aa383614(VS.85).aspx
    http://msdn.microsoft.com/en-us/library/aa446881(VS.85).aspx

    http://www.mvps.org/emorcillo/en/code/shell/tasksched.shtml

     

    Ji Zhou

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Tuesday, September 15, 2009 7:01 AM
    Moderator
  • Hi Zhou, I have checked the below links and i had used the Task Scheduler API also. http://msdn.microsoft.com/en-us/library/aa383614(VS.85).aspx http://msdn.microsoft.com/en-us/library/aa446881(VS.85).aspx But tat gives me the details of the local machine only, how to retrieve the Scheduled Tasks Details which are created by Scheduled Task Wizard in the remote machine. I had checked it with the remote machine, but still it gives me the local machine details Can u tell me how to check the Scheduled Tasks Details which are created by Scheduled Task Wizard in the remote machine using this Task Scheduler API or if any
    Tuesday, May 25, 2010 2:37 PM
  • ITaskScheduler has a SetTargetComputer method that need to call.
    Phil Wilson
    Tuesday, May 25, 2010 9:21 PM
  • Thanks for ur Update.. Will try it
    Wednesday, May 26, 2010 5:34 AM
  • What is the type of you obj ?
    -->
    obj = mc.GetInstances();
    
    Thursday, June 21, 2012 7:01 PM