Click here to Skip to main content
14,270,034 members
Rate this:
Please Sign up or sign in to vote.
See more: , +
hi guys i want to create a website[local] and one of its abilities must be taking screenshot from desktop (desktop of pc where IIS is running, totally i mean serverside desktop), you should say why serverside , answer is , i want to see my desktop from my mobile device when im downstairs to see if downloads are finished or not :D

i use this code in asp.net page in codebehind
int screenLeft = SystemInformation.VirtualScreen.Left;
        int screenTop = SystemInformation.VirtualScreen.Top;
        int screenWidth = SystemInformation.VirtualScreen.Width;
        int screenHeight = SystemInformation.VirtualScreen.Height;

        // Create a bitmap of the appropriate size to receive the screenshot.
        using (Bitmap bmp = new Bitmap(screenWidth, screenHeight))
        {
            // Draw the screenshot into our bitmap.
            using (Graphics g = Graphics.FromImage(bmp))
            {
                g.CopyFromScreen(screenLeft, screenTop, 0, 0, bmp.Size);
            }

            // Do something with the Bitmap here, like save it to a file:
            MemoryStream ms2 = new MemoryStream();
            bmp.Save(ms2, System.Drawing.Imaging.ImageFormat.Jpeg);
            bmp.Dispose();
            IMG.Src = "data:image/jpg;base64," + Convert.ToBase64String(ms2.GetBuffer());
            ms2.Dispose();
        }

when running from visual studio , its ok , it takes screen shots, but when i published website to local host its showing this error

Server Error in '/' Application.

The handle is invalid

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ComponentModel.Win32Exception: The handle is invalid

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[Win32Exception (0x80004005): The handle is invalid]
System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation) +781
System.Drawing.Graphics.CopyFromScreen(Int32 sourceX, Int32 sourceY, Int32 destinationX, Int32 destinationY, Size blockRegionSize) +35
ScreenShot.capture_Click(Object sender, EventArgs e) +334
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3707


any idea what to do??????? i am feeling its about permissions but how to set them , i donno...
Posted
Updated 28-Mar-14 7:46am
v3
Comments
idenizeni 28-Mar-14 15:04pm
   
When you push it to localhost the site runs under the IIS service which doesn't have a desktop to capture.

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Hi guys i found a way to solve this issue, i downloaded IIS 8.0 express from MS website and after setting its applicationhost.config for my website path and binding ip-port and giving firewall permissions to it , now i can take screenshot of my desktop :D thanks to all.
   
v2
Comments
ypv.ce 19-Aug-15 10:18am
   
can you please explain your answer in detail ?what to set on application host config and how to bind ip-port ?
Member 12756230 19-Apr-18 10:24am
   
Can you please explian how you do??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100