Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hello,

I want to get a list of all the AT scheduled tasks' application names.
I'm using NetScheduleJobEnum() and an array of AT_ENUM structs. But in my code, after running of NetScheduleJobEnum, buffPtr doesn't point to an AT_ENUM, and the line:
for(ai = buffPtr, cnt = 0; cnt < nrRead; cnt++, ++buffPtr)

doesn't run even one time. I'm attaching my code.
What is the problem?
Thanks
C++
DWORD res;
DWORD id;
DWORD maxid;
AT_ENUM* buffPtr = NULL;
AT_ENUM* ai;
DWORD nrRead;
DWORD posRead;
DWORD resumHandle;
DWORD cnt;
CString str;
ITaskScheduler *pITS;

hr = CoInitialize(NULL);

hr = CoCreateInstance(CLSID_CTaskScheduler,
                  NULL,
                  CLSCTX_INPROC_SERVER,
                  IID_ITaskScheduler,
                  (void **) &pITS);


res = ::NetScheduleJobEnum(NULL,
    (LPBYTE*)&buffPtr,
    MAX_PREFERRED_LENGTH,
    &nrRead,
    &posRead,
    &resumHandle);


if(res != 0) 
{
    int i;
}
else 

    for(ai = buffPtr, cnt = 0; cnt < nrRead; cnt++, ++buffPtr)
    {
        str.Format("Jobid: %d Command: %s", ai->JobId, ai->Command);
        ::AfxMessageBox(str);
    }

    if(buffPtr != NULL)
    {
        NetApiBufferFree(buffPtr);
    }
}
Posted
Updated 30-Mar-11 3:39am
v2

Is it a variant of your past Question get application names of AT jobs from scheduled tasks[^]?

Please see my Answer. I hope it will be helpful here as well.

It can be the problem of compatibility between versions of Task Scheduler. You scheduled tasks could be invisible to this code. The tasks are stored in different ways, depending on what utility or API you have used to schedule them. I suggest you use code samples for both versions of Task Scheduler API referenced in my past Answer.

—SA
 
Share this answer
 
v2
Comments
user_code 30-Mar-11 11:41am    
Hi, thanks for your answer.
I'll read and try your solution.

But can you see what's wrong with the code above? Or is the function NetScheduleJobEnum wrong?
Thanks
Sergey Alexandrovich Kryukov 30-Mar-11 16:46pm    
Hard to say. It will need time to test it. There is no exceptions, nothing, just empty set of tasks, right?
Please try both Microsoft samples first.
--SA
Beniwal01 11-Oct-12 5:03am    
res = ::NetScheduleJobEnum(L"\\\\AMITCH",
(LPBYTE*)&buffPtr,
MAX_PREFERRED_LENGTH,
&nrRead,
&posRead,
NULL);
i got value of res =0 that ok but i can not get job from my remote machine that AMITCH please tell me where i m wrong
Sergey Alexandrovich Kryukov 11-Oct-12 11:38am    
Is it the same as res == NERR_Success?
Could you do the following: schedule some tasks using the same API of the same version on some machine (could be local) and check up if your retrieval shows it correctly? As I say, if there is a compatibility problems, your API may not return all tasks. I remember that tasks added by Schtasks are no visible by the AT command. Please see:

http://en.wikipedia.org/wiki/Windows_Task_Scheduler,
http://en.wikipedia.org/wiki/At_%28Windows%29,
http://en.wikipedia.org/wiki/Schtasks.
--SA
C#
res = ::NetScheduleJobEnum(NULL,
    (LPBYTE*)&buffPtr,
    MAX_PREFERRED_LENGTH,
    &nrRead,
    &posRead,
    NULL);


if(res != 0)
{
    int i;
}
else

    for(ai = buffPtr, cnt = 0; cnt < nrRead; cnt++, ++buffPtr)
    {
        str.Format(L"Jobid: %d Command: %s", ai->JobId, ai->Command);
        ::AfxMessageBox(str);
    }

    if(buffPtr != NULL)
    {
        NetApiBufferFree(buffPtr);
    }

ULL)
{
NetApiBufferFree(buffPtr);
}
ULL)
{
NetApiBufferFree(buffPtr);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900