Answered by:
Screen capture of Server console screen

Question
-
Using VS 2012 and .NET 4.0 on Windows Server 2008 R2.
We leave the Admin user logged into the Server using remote desktop. The batch jobs run via the Task Scheduler as the Admin user, and any output is displayed on the Admin user screen. The Admin user screen is, of course, a disconnected Remote Desktop session.
I would like to setup a Task Scheduler job to capture the Admin user screen and email to me once a day. This would allow me to view any errors that did not get communicated to me via .NET exceptions.
I have code that will do a screen capture and write it to a file. It works locally. When I setup a scheduled job to run-as the Admin user, I get this error:
System.ComponentModel.Win32Exception (0x80004005): The handle is invalid
Here is the code:
Using bitmap As New Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height) Using g As Graphics = Graphics.FromImage(bitmap) g.CopyFromScreen(0, 0, 0, 0, bitmap.Size) End Using bitmap.Save("C:\temp\ScreenCapture.jpg", ImageFormat.Jpeg) End Using
Thanks for any ideas
MisterT99
Friday, September 12, 2014 9:23 PM
Answers
-
Seems the problem is caused at remote desktop because when you close the connection it automatically locks the remote desktop. That means since your desktop is locked even if you would be able to capture something it would be the lock screen.
There are some places you can take a look to overcome this:
http://stackoverflow.com/questions/5200341/capture-screen-on-server-desktop-session
- Edited by cnk_gr Saturday, September 13, 2014 8:04 AM
- Proposed as answer by Franklin ChenMicrosoft employee Monday, September 22, 2014 10:55 AM
- Marked as answer by Mister T99 Monday, September 22, 2014 10:59 AM
Saturday, September 13, 2014 8:03 AM
All replies
-
I also created a simple VB form project with a main sub (and deleted the default form).
My main sub is this:
Imports System.Drawing.Imaging Module Module1 Public Sub main() Using bitmap As New Bitmap(Screen.PrimaryScreen.WorkingArea.Width, Screen.PrimaryScreen.WorkingArea.Height) Using g As Graphics = Graphics.FromImage(bitmap) g.CopyFromScreen(0, 0, 0, 0, bitmap.Size) End Using bitmap.Save("C:\temp\ScreenCapture.jpg", ImageFormat.Jpeg) End Using End End Sub End Module
I scheduled the task as a simple task and it's running as my own user (administrator) and it run successfully.
Saturday, September 13, 2014 7:31 AM -
Seems the problem is caused at remote desktop because when you close the connection it automatically locks the remote desktop. That means since your desktop is locked even if you would be able to capture something it would be the lock screen.
There are some places you can take a look to overcome this:
http://stackoverflow.com/questions/5200341/capture-screen-on-server-desktop-session
- Edited by cnk_gr Saturday, September 13, 2014 8:04 AM
- Proposed as answer by Franklin ChenMicrosoft employee Monday, September 22, 2014 10:55 AM
- Marked as answer by Mister T99 Monday, September 22, 2014 10:59 AM
Saturday, September 13, 2014 8:03 AM -
Thanks for your help Franklin
MisterT99
Monday, September 22, 2014 10:59 AM