程序中如何调用windows“计划任务”向导

lookfeng 2003-01-14 05:26:15
谁告诉我?
...全文
319 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
lookfeng 2003-01-24
  • 打赏
  • 举报
回复
我已经自己解决问题,谢谢诸位。
cheng_young 2003-01-17
  • 打赏
  • 举报
回复
先手工添加一个任务: 计算器 否则以下程序出现错误Failed calling ITaskScheduler::Activate: error = 0x80070002

//win200 下通过
#include <windows.h>
#include <initguid.h>
#include <ole2.h>
#include <mstask.h>
#include <msterr.h>
#include <wchar.h>

int main(int argc, char **argv)
{
HRESULT hr = ERROR_SUCCESS;


///////////////////////////////////////////////////////////////////
// Call CoInitialize to initialize the COM library and then
// CoCreateInstance to get the Task Scheduler object.
///////////////////////////////////////////////////////////////////
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
CoUninitialize();
return 1;
}
}
else
{
return 1;
}


///////////////////////////////////////////////////////////////////
// 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;
}


///////////////////////////////////////////////////////////////////
// Call ITask::QueryInterface to retrieve the IProvideTaskPage
// interface, and call IProvideTaskPage::GetPage to retrieve the
// task page.
///////////////////////////////////////////////////////////////////
TASKPAGE tpType = TASKPAGE_TASK;
BOOL fPersistChanges = TRUE;
HPROPSHEETPAGE phPage;

IProvideTaskPage *pIProvTaskPage;
hr = pITask->QueryInterface(IID_IProvideTaskPage,
(void **)&pIProvTaskPage);
// Release the ITask interface.
pITask->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling ITask::QueryInterface: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}

hr = pIProvTaskPage->GetPage(tpType,
fPersistChanges,
&phPage);

// Release the IProvideTaskPage interface.
pIProvTaskPage->Release();

if (FAILED(hr))
{
wprintf(L"Failed calling IProvideTaskPage::GetPage: ");
wprintf(L"error = 0x%x\n",hr);
CoUninitialize();
return 1;
}


//////////////////////////////////////////////////////////////////
// Display the page using additional code
//////////////////////////////////////////////////////////////////

PROPSHEETHEADER psh;
ZeroMemory(&psh, sizeof(PROPSHEETHEADER));
psh.dwSize = sizeof(PROPSHEETHEADER);
psh.dwFlags = PSH_DEFAULT | PSH_NOAPPLYNOW;
psh.phpage = &phPage;
psh.nPages = 1;

int psResult = PropertySheet(&psh);
if (psResult <= 0)
{
wprintf(L"Failed to create the property page: ");
wprintf(L"0x%x\n", GetLastError());
}

CoUninitialize();
return 0;
}
lookfeng 2003-01-15
  • 打赏
  • 举报
回复
不知道就不要关税吗?
贴一堆无用的东西,累不累?
m_pDelphi 2003-01-15
  • 打赏
  • 举报
回复
seek "Task Scheduler [Task Scheduler], API described" in your MSDN
m_pDelphi 2003-01-15
  • 打赏
  • 举报
回复

Platform SDK: Task Scheduler
The Task Scheduler API
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. Note that the IScheduledWorkItem methods are inherited by the ITask interface.

Note Task Scheduler uses two standard COM interfaces: IUnknown and IPersistFile.

The IUnknown interface is supported by all Task Scheduler objects, and all Task Scheduler interfaces inherit its methods. It is used to retrieve pointers to other interfaces on a given object. These pointers are retrieved through calls to IUnknown::QueryInterface.

The IPersistFile interface (supported by the task object) is used to save a task to disk. Whenever you create a new task object or modify an existing task object, you must call IPersistFile::Save to store the task to disk.



Platform SDK Release: February 2001 Contact Platform SDK Order a Platform SDK CD Online


m_pDelphi 2003-01-15
  • 打赏
  • 举报
回复
Introduction to Microsoft Windows 2000 Server Task Scheduler
Microsoft Corporation

Updated March 1999

Summary: 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® Windows® 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® Windows® 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® 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 Window

You 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 Pages

So, 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 market 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 trademarks of Microsoft Corporation.

Other product or company names mentioned herein may be the trademarks of their respective owners.

Microsoft Corporation · One Microsoft Way · Redmond, WA 98052-6399 · USA


--------------------------------------------------------------------------------
Send feedback to MSDN.Look here for MSDN Online resources.
cheng_young 2003-01-15
  • 打赏
  • 举报
回复
在 MSDN platform SDK Documention->Setup and System Administration下有专门一部分是关于Task Scheduler的, 还有一些例子
lookfeng 2003-01-15
  • 打赏
  • 举报
回复
ITask不行,我已经试过。
RomanticProgrammer 2003-01-14
  • 打赏
  • 举报
回复
阿普
蝈蝈太阳 2003-01-14
  • 打赏
  • 举报
回复
UP
cheng_young 2003-01-14
  • 打赏
  • 举报
回复
如果不能直接调用, 研究一下ITask

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧