#include <stdio.h>
#include <windows.h>
#include <lmcons.h>
#include <lmat.h>
#pragma comment(lib,"NETAPI32.LIB")
void Jobadd(char * SysPath) //文件路径我们是从上面程序中获得
{
DWORD JobId;
AT_INFO ai;
long Len;
WCHAR szFilePath[256];
memset(&ai,0,sizeof(ai));
Len=MultiByteToWideChar(CP_ACP,0,SysPath,strlen(SysPath),
szFilePath,sizeof(szFilePath));
szFilePath[Len] = '\0'; //将路径转换成Unicode码
ai.Command=szFilePath;
ai.DaysOfMonth=0; //每个月的第几天
ai.DaysOfWeek=32; //1111111 七位二进制数,表示从周一到周日
ai.Flags=JOB_NONINTERACTIVE; //标志
ai.JobTime=1*60*60*1000+15*60*1000; //给ai结构变量各成员赋值
NetScheduleJobAdd(NULL,LPBYTE(&ai),&JobId); //添加任务计划
}
int main()
{
Jobadd("D:\\Programs\\bin\\firefox.bat"); //相应的文件路径
return 0;
}
其中AT_INFO结构内容可以从MSDN上查到,具体为http://technet.microsoft.com/zh-cn/aa370248