vascomakker
vascomakker

Reputation: 179

Console Application Args to Task Scheduler Parameters (CLOSED)

I've done a lot of research on this subject and all I found were misleading sites about information I wasn't looking for. So I hope anyone here can give me a solid explanation.

Basicly, I have a program, which I want to use in Task Scheduler. But whatever parameter I give in the box to put them in, it keeps saying The index is located outside of the array bounds.

I understand that parameters are linked to the args? So can anyone tell me what is wrong with my code?

public static void Main(string[] args)
{
   string paramList = string.Join("", args);
   string[] parameter = paramList.Split(',');

   string ScanPath = parameter[0]; //Which directory to scan
   string MailToAddress = parameter[1]; //Which e-mail to send the log to
   string ScanHours = parameter[2]; //How many hours to scan
}

I found this somewhere on codeproject. I assumed that the first arg is linked to the first parameter, etc, etc.

In Task Scheduler I basicly browse to the released executable: enter image description here

Of course the path and mail part is much longer when running the program, but this is just for example.

Do I need to remove the commas? And/or add - in front of every parameter? Or is it something completely else?

Thanks in advance!

Upvotes: 4

Views: 13897

Answers (2)

CSharpie
CSharpie

Reputation: 9467

Though i think you know this allready, just to be sure: You need to seperate parameters by blanks. Also if parameters contains blanks (path for example) put them in doublequotes.

Why dont you write a simple test-app that dumps the complete paramsarray into a textfile. Then you should know how to interprete correctly.

Upvotes: 1

C.Evenhuis
C.Evenhuis

Reputation: 26446

Usually command line arguments are split by a single space character, not comma's. Furthermore, if any of your arguments contain spaces, you need to wrap the argument in double quotes:

"C:\My Documents\xxx" [email protected] 10

I don't know how the task scheduler supplies its parameters, but you could of course log the arguments before using them, to see exactly what's passed to your application.

Upvotes: 5

Related Questions