Click here to Skip to main content
15,919,774 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi..

i try to schedule the task using windows API..

when i use following program it create the task in window..

But function return failure..


i can't find the reason. .and also the task gives error as "Could Not start"

coding is:

C++
#include "stdafx.h"
#include <stdio.h>
#include <windows.h>
#include <lm.h>
#include <Lmat.h>
#include <AtAcct.h>
int main(int argc, char* argv[])
{
    AT_INFO s;
    LPDWORD  jobid;
    LPBYTE s1;


    s.JobTime = 42000000;
    s.DaysOfMonth = 11;
    s.DaysOfWeek = 1;
    s.Flags = JOB_ADD_CURRENT_DATE;
    s.Command = (unsigned short*)"C:\\idle.exe";
    //printf("%s",s.Command);
    char chName[100] = "dharmaraj";
    char chPwd[100] = "dharmaraj";


 if(NERR_Success == NetScheduleJobAdd(NULL,(LPBYTE)&s,jobid))
 {
     printf("sucess");
 }
 else
 {
     printf("faliure");
 }

    printf("Jobid %d\n",jobid);
    return 0;
}
Posted
Updated 8-Nov-11 19:36pm
v2

Few issues.

1) (unsigned short*)"C:\\idle.exe" is not how you do Unicode strings. You put an L in front of it, like L"C:\\idle.exe"

2) The final parameter, jobid, is an output parameter.
C++
DWORD jobid; //Not LPDWORD
NetScheduleJobAdd(NULL,(LPBYTE)&s,&jobid)

This gives it the address of the variable jobid, so it can save the output value in it.

1 more thing, you are missing the line feed in the printf, so everything is squished up on the one line. Should be printf("sucess\n");
 
Share this answer
 
Comments
@BangIndia 9-Nov-11 1:59am    
Thanks
What I can see right now: JobTime must be a pointer to a value; and you are assigning some integer; same thing about jobid: you pass uninitialized pointer, but it should point to some
DWORD<code> value.<br />
<br />
<dd>—SA</dd>
 
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