Click here to Skip to main content
11,411,922 members (59,378 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: WinXP C++ Scheduler
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
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 30-Mar-11 4:37am
Edited 30-Mar-11 4:39am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
  Permalink  
v2
Comments
erez_l at 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
SAKryukov at 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 at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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);
}
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 268
1 Sergey Alexandrovich Kryukov 200
2 Sascha Lefévre 170
3 ProgramFOX 130
4 Maciej Los 110
0 Sergey Alexandrovich Kryukov 8,955
1 OriginalGriff 7,158
2 Maciej Los 3,480
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web04 | 2.8.150414.5 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100