Start applications via windows task scheduler

0

I have a C# console application which starts the some of windows desktop applications say for example notepad, Skype. I have created a basic task in windows task scheduler and then gave when i log on as trigger and pointed to my console exe. But the application not getting triggered when i log on.

Below was my code in void main

ProcessStartInfo info = new ProcessStartInfo("C:\\Windows\\System32\\notepad.exe");
Process.Start(info);
ProcessStartInfo process2 = new ProcessStartInfo("C:\\Program Files (x86)\\Skype\\Phone\\Skype");
Process.Start(process2);

Let me know if i was unclear/Misunderstood.

selva

Posted 2015-09-12T14:46:28.697

Reputation: 33

I have edited the code. – selva – 2015-09-12T15:02:16.360

Show what you have configured in your Task Manager's task. I suppose you have not enabled interaction with desktop. Check your processes with Process Explorer after logon. Check your event log in Computer management. – Maximus – 2015-09-12T19:22:32.977

Answers

0

I am assuming the exe works fine when not called from the Task Scheduler (TS)? Try creating a ".cmd" or ".bat" file. Add your console exe and execute ("start") from inside the new batch file.

Example - Task Scheduler batch file to start skype - replace with your console exe:

@echo off
start "My EXE Console Window Title" "C:\Program Files (x86)\Skype\Phone\skype.exe"

Call the batch file (not exe) from your TS. Does it work now?

Which also brings up an aside from your direct question: You do realize you can just write a batch file to start those applications when you login (from TS) - why have another exe do it? Or you could even just add win apps individually to the TS? OR you could simply add to startup.

Consult http://ss64.com/nt/start.html for some batch 'start' options to call EXE or "start /?" for command help in CMD.

bshea

Posted 2015-09-12T14:46:28.697

Reputation: 678

Yes when debugging the code works fine . And also i don't have any idea accomplishing this task in optimal way so that only i prefered exe. – selva – 2015-09-12T15:18:03.123

Edited answer a bit. Try the batch file method to start your exe.. – bshea – 2015-09-12T15:22:11.993

I have created a batch file with the code you have given and pointed that in Task Scheduler but i opens the cmd instead of application – selva – 2015-09-12T15:34:09.010

My feeling is the exe (since it's console only) needs to execute CMD and TS has issue with that. you could also try adding to TS using your exe as a parameter to cmd. = "cmd c:\path\your.exe" – bshea – 2015-09-12T15:34:21.497

^ "I have created a batch file.." -> Yes it will open cmd to execute the batch file. Try this- open cmd/console. run the batch file manually. does it start your exe? If not something isn't right in batch file. – bshea – 2015-09-12T15:37:05.540

echo off start "C:\Program Files (x86)\Skype\Phone\skype"

This was the code when i give start bat file path in cmd it creates two more cmd . Don't know what went wrong – selva – 2015-09-12T15:50:47.077

Too many comments -Go here https://gist.github.com/bmatthewshea/45b5192d1c57dbaa116e

– bshea – 2015-09-12T16:43:12.340