任务计划程序 [英] Task Scheduler
问题描述
我在Vista(RC1)中的应用程序中使用任务计划程序时遇到问题.我可以获取任务计划程序对象,但是当我尝试激活特定的任务时,会收到0x80070005(访问冲突)代码,其中包含应用程序失败的代码.
I have a problem using the task scheduler from an application in Vista(RC1). I'm able to get the task scheduler object but when I try to activate the specific task I get 0x80070005 (access violation) the code to where the application fails is included below.
有人知道为什么这在Vista中不起作用吗? (在2000/XP上工作正常)
Does anyone have any idea why this doesn't work in Vista? (Works just fine on 2000/XP)
也请注意!
此应用程序是通过控制面板小程序(cpl文件)编译的.
Also note!
This application is complied ti a Control Panel applet (cpl-file)
代码提取:
HRESULT hr = ERROR_SUCCESS;
布尔 bReturn = false ;
HRESULT phrStatus;
ITask * pITask;
LPCWSTR lpcwszTaskName;
//初始化COM库.
ITaskScheduler * pITS;
hr = CoInitialize(NULL);
如果(SUCCEEDED(hr))
{
//获取任务计划程序对象.
hr = CoCreateInstance(CLSID_CTaskScheduler,
nbsp; bsp ; NULL,
&bb CLSCTX_INPROC_SERVER,
; IID_ITaskScheduler,
b ( void **)& pITS);
如果(FAILED(hr))
{
AfxMessageBox(无法获取任务计划程序.");
CoUninitialize();
返回 b返回;
}
}
其他
{
AfxMessageBox(无法初始化COM库");
返回 b返回;
}
HRESULT hr = ERROR_SUCCESS;
bool bReturn = false;
HRESULT phrStatus;
ITask *pITask;
LPCWSTR lpcwszTaskName;
// Initialize the COM library.
ITaskScheduler *pITS;
hr = CoInitialize(NULL);
if (SUCCEEDED(hr))
{
// Get the Task Scheduler object.
hr = CoCreateInstance(CLSID_CTaskScheduler,
NULL,
CLSCTX_INPROC_SERVER,
IID_ITaskScheduler,
(void **) &pITS);
if (FAILED(hr))
{
AfxMessageBox("Unable to get task scheduler.");
CoUninitialize();
return bReturn;
}
}
else
{
AfxMessageBox("Unable to initialize the COM library");
return bReturn;
}
//获取任务对象.
lpcwszTaskName = L"Hernis WatchDog";
hr = pITS->激活(lpcwszTaskName,
&nsp ; &bsp; nsp (IUnknown **)& pITask);
// Get the Task object.
lpcwszTaskName = L"Hernis WatchDog";
hr = pITS->Activate(lpcwszTaskName,
IID_ITask,
(IUnknown**) &pITask);
//释放ITaskScheduler界面.
pITS-> Release();
//找不到任务.
如果(FAILED(hr))
{
//出于调试目的的一些输出.
字符 szDebug [256];
如果(0x80070002 == hr)
sprintf(szDebug,未找到文件");
否则为(0x80070005 == hr)
sprintf(szDebug,访问被拒绝.");
否则为(E_INVALIDARG == hr)
sprintf(szDebug,"pwszName参数无效.");
否则,如果(E_OUTOFMEMORY == hr)
sprintf(szDebug,内存分配失败.");
否则(SCHED_E_UNKNOWN_OBJECT_VERSION == hr)
sprintf(szDebug,任务对象版本不受支持或无效.");
其他
sprintf(szDebug,"Error = 0x%x",hr);
// Release ITaskScheduler interface.
pITS->Release();
// Could not find task.
if (FAILED(hr))
{
// Some output for debugging purposes.
char szDebug[256];
if (0x80070002 == hr)
sprintf(szDebug, "File not found");
else if (0x80070005 == hr)
sprintf(szDebug, "Access denied.");
else if (E_INVALIDARG == hr)
sprintf(szDebug, "The pwszName parameter is not valid.");
else if (E_OUTOFMEMORY == hr)
sprintf(szDebug, "A memory allocation failed.");
else if (SCHED_E_UNKNOWN_OBJECT_VERSION == hr)
sprintf(szDebug, "The task object version is either unsupported or invalid.");
else
sprintf(szDebug, "Error = 0x%x", hr);
AfxMessageBox(szDebug);
CoUninitialize();
返回 b返回;
}
//由于我们无法获得任务对象,因此不会执行其余代码
AfxMessageBox(szDebug);
CoUninitialize();
return bReturn;
}
// Rest of code will not get executed since we cannot get an task object.
推荐答案
我在VISTA build 5744中的任务计划代码中遇到了相同的问题.ITaskScheduler-> Activate返回 在Vista中为E_ACCESSDENIED.它在 XP/2000.我真的很了解这与加强Vista中的安全性有关.我使用CoInitializeSecurity()进行了一些试验. 但是它没有做任何改变.
I am facing same problem in my task scheduling code in VISTA build 5744. ITaskScheduler->Activate returns E_ACCESSDENIED in Vista. It works just fine in XP/2000. I really understand that it is regarding the tightened security in Vista. I made some trials using CoInitializeSecurity(). But it doesn't made any changes.
这篇关于任务计划程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!