×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Email Screen Image From a Sheduled Task

Email Screen Image From a Sheduled Task

Email Screen Image From a Sheduled Task

(OP)
Windows Server 2008 R2. I have a .Net app that I want to run from a scheduled task. What I am trying to do is display a form and copy the form image to a file and email it. This works fine from a batch file or manually starting the app. the task bombs out at

CODE

oForm.ShowDialog() 
I have code in the form to save the form image, email the image and close the form. From my testing I'm guessing I can't display anything on the screen when running from a scheduled task. Is there any way around this or another method to do this?

Auguy
Sylvania/Toledo Ohio

RE: Email Screen Image From a Sheduled Task

I have been trying and I am unable to replicate the issue. I set up a simple program that runs from Sub Main(), opens one form with ShowDialog, and then that form opens another with ShowDialog. All of that worked with no problem. Could you post the settings of the scheduled task?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

RE: Email Screen Image From a Sheduled Task

A scheduled task doesn't always have a desktop to interact with

RE: Email Screen Image From a Sheduled Task

After some more testing, I can get the InvalidOperationError if I set the Scheduled Task to "Run whether user is logged on or not". It errors whether I run it with my user account, a Domain Admin account that is added as a local Admin, or the local Admin account. n If I set it to "Run only when user is logged on" it runs fine.

I found this batch script:

@echo off
echo %date% %time% Start of task > c:\test.log
echo User=%UserName%, Path=%path% >> c:\test.log
c:\Tools\YourTask.exe 1>>c:\test.log 2>c:\test.err
echo ErrorLevel of c:\Tools\YourTask.exe=%ErrorLevel% >> c:\test.log
echo %date% %time% End of task >> c:\test.log

Put that in a .bat file, change the application to yours (replace c:\Tools\YourTask.exe, there are 2 references), modify the task to run the batch file, and it will create a log file and an error file. The error file that mine created has this:

Unhandled Exception: System.InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at TaskSchedulerTest.Module1.main()

So in this case it is indeed what strongm said: there is no desktop (i.e., not running in UserInteractiveMode), so the program cannot display a form.

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

RE: Email Screen Image From a Sheduled Task

(OP)
Thanks for the thorough investigation. I was afraid this might be the case.

Auguy
Sylvania/Toledo Ohio

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close