0x1: An incorrect function was called or an unknown function was called

I've an error related with Sheduled tasks in windows server 2003.

I'm using Microsoft.Win32.TaskSheduler.dll to add a bat file to the Sheduled tasks.

When I add the file manually, there is no problem but when i try to add the file via code(I'm using C#).

Here is the code i'm using:

TaskService ts = new TaskService();

TimeTrigger tt = new TimeTrigger();
tt.StartBoundary = DateTime.Now;

tt.Enabled = true;
tt.Repetition.Duration = TimeSpan.FromMinutes(5);
tt.Repetition.Interval = TimeSpan.FromMinutes(1);

// Create a new task definition and assign properties
TaskDefinition td = ts.NewTask();

string exec_action = "c:\folder\file.bat"

new ExecAction(exec_action,
null, null

string taskName = "taskName";

ts.RootFolder.RegisterTaskDefinition(taskName, td
null, null,

In the string exec_action, if i put there "notepad.exe", the task "fires" and the note pad opens, but if i put there the bat file, i see the cmd console opening and closing very fast but nothing happens.
If i run the bat file with "double click" it also works well.

I don't know what i'm missing here, if someone can help me, i would be thankful!
2 answers Last reply
More about incorrect function called unknown function called
  1. Have you tried making the exec_action "cmd" and then using the /C switch to specify the batch file?
  2. Ijack said:
    Have you tried making the exec_action "cmd" and then using the /C switch to specify the batch file?

    I've solverd the problem! :)

    The problem was in the bat file.

    The bat file calls a "exe" file . They are both located in the same directory.

    So in the bat file i had only put the name of the "exe" and not the complete file path.
    TaskSheduler runs in the system32 folder, so it needs the complete path of the "exe".

    And that's it...problem solved!!

    The complete path of the "exe" file was all i needed.

Ask a new question

Read More

Configuration Windows Server 2003 Windows XP