调度任务在C中失败 [英] scheduling task got failure in c

查看:101
本文介绍了调度任务在C中失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi ..

我尝试使用Windows API安排任务..

当我使用以下程序时,它将在窗口中创建任务.
但是函数返回失败..


我找不到原因. .并且该任务还会显示错误消息无法启动"

编码为:

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:

#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;
}

推荐答案

问题很少.

1)(unsigned short*)"C:\\idle.exe"不是您如何处理Unicode字符串.您将L放在其前面,例如L"C:\\idle.exe"

2)最终参数jobid是输出参数.
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.
DWORD jobid; //Not LPDWORD
NetScheduleJobAdd(NULL,(LPBYTE)&s,&jobid)


这为它提供了变量jobid的地址,因此可以在其中保存输出值.

还有1件事,您缺少printf中的换行符,因此所有内容都压缩在一行中.我现在应该看到的应该是printf("sucess\n");


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");


:JobTime必须是一个指向值的指针;并且您正在分配一些整数;关于jobid的同样事情:您传递未初始化的指针,但是它应该指向某些
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>


这篇关于调度任务在C中失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆