windows的Task Scheduler 服务是在指定时间内运行指定命令,现在我要读取其中内容,包括,命令的时间,内容,执行时间等等信息。我要的是读取,不是添加。

解决方案 »

  1.   

    Enumerating Tasks Example. To enumerate tasks, you must call ITaskScheduler::Enum
    to create an enumeration object. ... (This example assumes that the Task Scheduler service
    is running.); Call ITaskScheduler::Enum to get an enumeration object
    msdn.microsoft.com/library/en-us/ taskschd/taskschd/enumerating_tasks_example.asp
      

  2.   

    #include <windows.h>
    #include <initguid.h>
    #include <ole2.h>
    #include <mstask.h>
    #include <msterr.h>
    #include <wchar.h>
    #define TASKS_TO_RETRIEVE          5
    int main(int argc, char **argv)
    {
      HRESULT hr = S_OK;
      ITaskScheduler *pITS;
      /////////////////////////////////////////////////////////////////
      // Call CoInitialize to initialize the COM library and 
      // then CoCreateInstance to get the Task Scheduler object. 
      /////////////////////////////////////////////////////////////////
      hr = CoInitialize(NULL);
      if (SUCCEEDED(hr))
      {
        hr = CoCreateInstance(CLSID_CTaskScheduler,
                              NULL,
                              CLSCTX_INPROC_SERVER,
                              IID_ITaskScheduler,
                              (void **) &pITS);
        if (FAILED(hr))
        {
          CoUninitialize();
          return hr;
        }
      }
      else
      {
        return hr;
      } 
      /////////////////////////////////////////////////////////////////
      // Call ITaskScheduler::Enum to get an enumeration object.
      /////////////////////////////////////////////////////////////////
      IEnumWorkItems *pIEnum;
      hr = pITS->Enum(&pIEnum);
      pITS->Release();
      if (FAILED(hr))
      {
        CoUninitialize();
        return hr;
      } 
      /////////////////////////////////////////////////////////////////
      // Call IEnumWorkItems::Next to retrieve tasks. Note that 
      // this example tries to retrieve five tasks for each call.
      /////////////////////////////////////////////////////////////////
      LPWSTR *lpwszNames;
      DWORD dwFetchedTasks = 0;
      while (SUCCEEDED(pIEnum->Next(TASKS_TO_RETRIEVE,
                                    &lpwszNames,
                                    &dwFetchedTasks))
                      && (dwFetchedTasks != 0))
      {
        ///////////////////////////////////////////////////////////////
        // Process each task. Note that this example prints the 
        // name of each task to the screen.
        //////////////////////////////////////////////////////////////
        while (dwFetchedTasks)
        {
           wprintf(L"%s\n", lpwszNames[--dwFetchedTasks]);
           CoTaskMemFree(lpwszNames[dwFetchedTasks]);
        }
        CoTaskMemFree(lpwszNames);
      }
      pIEnum->Release();
      CoUninitialize();
      return S_OK;
    }通过这个程序能够获得几个任务,任务名,如何读取其任务的EXE,任务时间,任务路径等其他属性呢?麻烦各位了!
      

  3.   

    IScheduledWorkItem interface
    The Task Scheduler API consist of several COM objects and their associated interfaces. The following illustration shows a task scheduler object, which represents the Task Scheduler service; an enumeration object and task object, which are created by ITaskScheduler method calls; and a task trigger object, which is created by IScheduledWorkItem method calls
      

  4.   

    楼上老兄好事做到底,能否给个简单的调用IScheduledWorkItem的例子呢?MSDN上面没有例子看:(
      

  5.   

    ///////////////////////////////////////////////////////////////////
      // Call ITaskScheduler::Activate to get the Task object.
      ///////////////////////////////////////////////////////////////////
      ITask *pITask;
      LPCWSTR lpcwszTaskName = L"计算器";
      hr = pITS->Activate(lpcwszTaskName,
                          IID_ITask,
                          (IUnknown**) &pITask);
      
      // Release the ITaskScheduler interface.
      pITS->Release();
      
      if (FAILED(hr))
      {
        wprintf(L"Failed calling ITaskScheduler::Activate: ");
        wprintf(L"error = 0x%x\n",hr);
        CoUninitialize();
        return 1;
      }
      

  6.   

    Introduction to Microsoft Windows 2000 Server Task Scheduler
    Microsoft CorporationUpdated March 1999Summary: This article is intended for software developers and system integrators. It describes the Task Scheduler, a new service and user interface that runs on the Microsoft&reg; Windows&reg; operating systems. (5 printed pages)Introduction
    Why Do We Need Another Scheduler?
    Every new system or application offers some kind of scheduling service, something that automatically invokes scripts or programs at specified times. The most common, and in many ways the least useful, is the StartUp program group, present in all of the Microsoft&reg; Windows&reg; operating systems. The problem with the StartUp group and all the other schedulers is that they are all designed for different needs and are rarely built to integrate with all the components in a system, or work seamlessly in more than one system. The Windows 95 Plus! Pack provided the System Agent that included a user interface as well as a set of application programming interfaces (APIs). Windows NT&reg; came with the AT command, not an especially user-friendly tool that required a fair amount of familiarity with the arcane world of the command prompt. Many applications provide a place for users to configure some scheduling mechanism for performing recurring, necessary maintenance tasks. None of these schedulers work well together, and few provide any programmable interfaces.A Common, Flexible, and Extensible Interface
    Task Scheduler provides a friendly user interface (see Endnote) that is the same one on both Windows and Windows NT, with the exception of added security features in Windows NT and Windows 2000. The interface is fully integrated into the operating system, and is accessible from the My Computer icon on your desktop. Users can drag-and-drop programs right into Task Scheduler to quickly add a new task or use the provided "Create Scheduled Task" wizard.Figure 1. Task Scheduler Main WindowYou can schedule any script, program, or document to be invoked at any time or any interval, every day to once a year, and on events like system boot, user logon, or system idle. A task is saved as a file with a .job extension, which enhances the ability to move from computer to computer. Administrators can create scheduled maintenance task files and place them where needed. You can access the Task Folder remotely from the Network Neighborhood as well as send tasks in e-mail.On Windows NT and Windows 2000, scheduled tasks are created and executed based on standard security permissions. Tasks are persisted as files and are configurable by NTFS access control lists (ACLs) to set who can view, delete, modify, or use them. The items that make up the task, the scripts, programs, and documents, are also still controlled by whatever ACLs are present. Under Windows NT and Windows 2000, this provides a high degree of control over how files are accessed.Note   When you move a .job file on a Windows NT or Windows 2000-based system, a user's credentials will not transfer with the file. They must be reentered after moving the file. This is because the credentials are not stored with the task, but by the security system of the operating system.Since Windows NT and Windows 2000 are multiuser environments, when tasks are created, a user name and password are required that will set the current security context in which the task will execute. This allows multiple tasks to run on a single computer in the security context that was supplied. Multiple users can each have their own individual scheduled tasks.Why Should Developers Be Interested?
    Task Scheduler provides a common and fully programmable set of interfaces. Task Scheduler is a COM-based object, which adds all the advantages of COM, including language and platform independence (as well as remote capabilities provided by DCOM). If you are developing an application to run under both Windows and Windows NT, you can write to the same interfaces regardless of the platform.All of the functionality in Task Scheduler is completely accessible from these APIs. This means you don't have to "rewrite the wheel" when you want to add scheduling services to your applications. You can be assured that the scheduling services will already be there in the operating system and that they'll be robust, stable, and, over subsequent releases, more feature-rich.Finally, with Task Scheduler you don't even have to write your own scheduling property pages. You can invoke Task Scheduler's property pages from the same APIs. You can create the property pages and dialog boxes that are specific to your application and then invoke Task Scheduler's property pages as needed.Figure 2. One of Task Scheduler's Property PagesSo, How Do I Get It?
    The Task Scheduler user interface is available in the Internet SDK client and the Platform SDK at http://msdn.microsoft.com/developer/sdk/.Summary
    The goal of the Task Scheduler team is to unify a set of disparate tools to make a user's experience more consistent and satisfying. By providing common APIs across platforms, Microsoft hopes to help developers in building their applications and adding scheduling services—virtually for free. Robust, cross-platform, flexible scheduling is one less thing you have to create from scratch.For More Information
    For the latest information on Windows, check out our World Wide Web site at www.microsoft.com/windows/.For the latest information on Windows NT Server, check out our World Wide Web site at www.microsoft.com/ntserver/ or the Windows NT Server Forum on the Microsoft Network (GO WORD: MSNTS).Endnote. The item that is different at this time is that Win9X has an idle trigger. This will be the same with the release of Windows 2000.--------------------------------------------The information contained in this document represents the current view of Microsoft Corporation on the issues discussed as of the date of publication. Because Microsoft must respond to changing et conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information presented after the date of publication.This article is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS DOCUMENT.The BackOffice logo, Microsoft, Windows, and Windows NT are registered trades of Microsoft Corporation.Other product or company names mentioned herein may be the trades of their respective owners.Microsoft Corporation · One Microsoft Way · Redmond, WA 98052-6399 · USA
    --------------------------------------------------------------------------------
    Send feedback to MSDN.Look here for MSDN Online resources.
      

  7.   

    而通过上面的程序读出的任务都是这样命名的:1.job 2.job之类的,难道是
      ITask *pITask;
      LPCWSTR lpcwszTaskName = L"1.job";
    我试过了,好像不行哦,lpcwszTaskName后面究竟应该填什么呢??谢谢:)