Question

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 server side 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...

Was it helpful?

Solution 2

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.

OTHER TIPS

My first reaction was to say, it's not possible, but since you managed to do that in VS, may be it is..

To setup the user, in the IIS you need to go to Application Pools -> right click on the application pool that your site is using (by default it's ASP.NET V4.0 Integrated) -> Advanced settings -> find the setting called Identity, click on the [...] and then in the new popup click the radio button Custom account, and set your user account there.

If that doesn't solve the problem, I don't think anything will

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top