Solved

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

Posted on 2010-09-20
13
1,466 Views
Last Modified: 2012-05-10

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,

eg

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

http://support.microsoft.com/kb/313565


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.


http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/2003_Server/Q_24100023.html

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_23021339.html
0
Comment
Question by:darbid73
  • 8
  • 5
13 Comments
 
LVL 41

Accepted Solution

by:
graye earned 500 total points
ID: 33717175
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?
0
 
LVL 19

Author Comment

by:darbid73
ID: 33722795
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.


0
 
LVL 41

Expert Comment

by:graye
ID: 33724234
So, what happens if you use the "normal" scheduled task interface? (Control Panel, Admin Tools, Task Scheduler)
0
 
LVL 19

Author Comment

by:darbid73
ID: 33724244
works 100%
0
 
LVL 41

Assisted Solution

by:graye
graye earned 500 total points
ID: 33724919
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")
http://www.windowsnetworking.com/kbase/WindowsTips/WindowsXP/AdminTips/Utilities/XPschtaskscommandlineutilityreplacesAT.exe.html
Doctor, Doctor... it hurts when I raise my arm.   Well, then don't raise your arm!
0
 
LVL 19

Author Comment

by:darbid73
ID: 33725039
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.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 41

Assisted Solution

by:graye
graye earned 500 total points
ID: 33727374
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?
0
 
LVL 19

Author Comment

by:darbid73
ID: 33732398
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.
0
 
LVL 19

Author Comment

by:darbid73
ID: 33732737
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.
0
 
LVL 41

Assisted Solution

by:graye
graye earned 500 total points
ID: 33733107
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!
0
 
LVL 19

Author Comment

by:darbid73
ID: 33733185
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 :-)....
0
 
LVL 19

Author Comment

by:darbid73
ID: 33733444
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.
0
 
LVL 19

Author Comment

by:darbid73
ID: 33734299
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.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now