Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
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

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.
 
Share this answer
 
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??
Member 12472175 14-Nov-19 5:30am    
can you please explain your answer in detail ?
And what to set on application host config and how to bind ip-port ?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900