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 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?
CODE
oForm.ShowDialog()
Auguy
Sylvania/Toledo Ohio
RE: Email Screen Image From a Sheduled 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
RE: Email Screen Image From a Sheduled Task
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
Auguy
Sylvania/Toledo Ohio