Task Scheduler starts - initiates code - code does nothing - Last Run Result = e0434f4d

I have a small .exe built with 3.5 .Net target.  Debugs fine and when built the .exe also.  I am assuming it is not the problem.

My next task is to have code that will make a scheduled task

For simplicity I chose AT to make the task,


command = "at 12:55 /interactive /every:M,T,W,Th,F ""%ProgramFiles%\path\test.exe"""


The task runs, my little .exe can be found in the task manager, but no code is actually run.

The Last run result is e0434f4d

My research found these but I do not understand them.


LVL 20
Who is Participating?
grayeConnect With a Mentor Commented:
Modern versions of Windows do not allow for any user interaction in schedule tasks.... so a normal "WinForm" will have trouble.   Instead, you should use write your application as a "Console Application"
Can you verify that the application runs from the command prompt on the same machine where you're running it as a scheduled task?
darbid73Author Commented:
Yes it runs from the command prompt.  

If I create the task my self manually with my username and password then the programs and TASK runs properly.

The problem is that an AT made task does not run.  My code to make my AT task is above.

So I assume that it is a user/authority problem.  I am currently on XP but I am gearing up for Windows 7 and need to be able to distribute my code to create this task on other computers.

So, what happens if you use the "normal" scheduled task interface? (Control Panel, Admin Tools, Task Scheduler)
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

darbid73Author Commented:
works 100%
grayeConnect With a Mentor Commented:
So, it's just the AT command that giving you problems?   If so, then don't use the AT command, and use the "normal" GUI interface to creating scheduled tasks.  If you need to perform this step from the command line, then I'd recommend that you use the new Schtasks utility (the AT command is "depreciated")
Doctor, Doctor... it hurts when I raise my arm.   Well, then don't raise your arm!
darbid73Author Commented:
Dr. Doctor,

I am an idiot and like raising my arm - please help me.

I have too found Schtasks for any one interested - http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/schtasks.mspx?mfr=true

I want to put tasks on other computers so the GUI is not an option.  The bit I am having trouble with is how to get a task to run withOUT the users password.  

I am in a work environment where people log onto their computer. it is possible because i recently installed iTunes and their little task runs and I never gave them my password.
grayeConnect With a Mentor Commented:
Well, you can configure a scheduled task to run with the Local System (or Network System) account.... which does not require a password.
Tell us more about the app... anything special?  Does it require access to the currently logged in user's files?
darbid73Author Commented:
I dont want to bombard you with all my code, that would be too much to ask.

My code does start with "GetFolderPath(SpecialFolder.ProgramFiles)"  I am not sure if that is user specific in XP or Win7

Immediately after that I have a MSGBOX function to know if the code has started and I do not even get this if I make the RUN AS:  "NT AUTHORITY\SYSTEM"

What you are saying is that if I use the SYSTEM to run it, then I have to think of the system as another user and only do things that the system is allowed to do on this computer?  Thus later in my code it queries a SQL Server - I am pretty sure the SYSTEM will not have access to this server.  In theory am I on the right track here?

If that is correct then using the System is not an option.  Then next thing I have noticed is you do not have to use a password if "RUN ONLY IF LOGGED ON" is checked.  

My question; Schtasks does not appear to let you use this? Am I correct?

I think how I need to do this is create a .log file (task) with "RUN ONLY IF LOGGED ON" checked.

In my install code copy this file to the taks folder, then use Schtasks to add the USERs name to RUN AS:

How does that sound to you?  I will have to check how to get the username from the Environment but I hope I can.
darbid73Author Commented:
Scrap this bit;

"I think how I need to do this is create a .log file (task) with "RUN ONLY IF LOGGED ON" checked.

In my install code copy this file to the taks folder, then use Schtasks to add the USERs name to RUN AS:

How does that sound to you?  I will have to check how to get the username from the Environment but I hope I can."

If I use that .log file and change the RUN AS the dam thing wants a password.
grayeConnect With a Mentor Commented:
Hang on... let's back up a wee bit.
Modern versions of Windows do not allow Scheduled tasks to interact with the user.   That's why I asked if this was a "windows form" application or a "console" application.   If your application is using a MessageBox, then you are definately interacting with a user!
darbid73Author Commented:
No problem but why do you use "Modern versions of Windows" is that expert speak :-) Is XP modern or Win 95 the start of the Modern Versions? In any case I am currently working in XP and know that it will have to work in Win 7.

My application does currently have a msgbox and also uses the system tray so I am wanting to have interaction with the USER.  So I suppose the NT AUTHORITY\SYSTEM is not an option.

I am not an experienced coder but I am coming from the position that if I can manually do this I can code it.

I can manually add a new task, check "RUN ONLY IF LOGGED ON" and I am not required to enter my password.  Further this runs ok.

Further Google and Apple iTunes can set tasks on this computer without me knowing and I get a nice big Apple update window, so it has user interactivity.  If the big boys can do it so can I :-)....
darbid73Author Commented:
Graye -  I think I will close this thread accepting your answer here as close to the answer 33724919

In my opinion the answer to this question is - you cannot create a scheduled task from the command line for a task that starts a program with interactivity without a username and password.

Both AT and Schtasks allow either a SYSTEM user task = no user interactivitry and no network access OR AT and Schtasks allow tasks with user interactivity provided you supply a username and password.
darbid73Author Commented:
Actually I wanted to add that AT Command actually will work if you call a .BAT file that calls my .exe as long as the "/interactive" command is given in AT.

So then the annoying things start again....AT is depreciated and "interactive" is not available in Schtasks.  Great.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.