none
Remote Screenshot. RRS feed

  • Question

  • Hello Scripting guys, 

    I have the below script to take screenshots, I was trying to use it remotely so I can check the status of the server with an screen, (something similar to the Azure Screenshot), but when run it through Invoke-Command or PSsession I've receive the following error: Exception calling "CopyFromScreen" with "5" argument(s): "The handle is invalid", I've tried to search info about it but i did not found anything helpful. Could you please help me on this?

    Remote Script:

    Invoke-Command -ComputerName SERV01 -Credential ADMIN1 -ScriptBlock {
    [Reflection.Assembly]::LoadWithPartialName("System.Drawing")
    function screenshot([Drawing.Rectangle]$bounds, $path) {
       $bmp = New-Object Drawing.Bitmap $bounds.width, $bounds.height
       $graphics = [Drawing.Graphics]::FromImage($bmp)
       $graphics.CopyFromScreen($bounds.Location, [Drawing.Point]::Empty, $bounds.size)
       $bmp.Save($path)
       $graphics.Dispose()
       $bmp.Dispose()
    }
    $bounds = [Drawing.Rectangle]::FromLTRB(0, 0, 1000, 900)
    screenshot $bounds "C:\windows\temp\screenshot.png"
    Invoke-Item C:\windows\temp\screenshot.png
    Start-Sleep -s 5
    Remove-Item C:\windows\Temp\screenshot.png

    Thanks, best regards.

    Friday, November 4, 2016 5:57 PM

Answers

  • That only works in a form.


    \_(ツ)_/

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 6:36 PM
  • mmm so if i create a GUI with, let say a button, and place this code on the form it will work?? lol

    If I run it locally on my pc it works

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:12 PM
  • In a remote session there is no screen so nothing can be captured.

    I have never tried to do a screenshot like that.  Yes - it might work locally without a form but not remotely.

    You can place the script on a share and have the user run it for a screenshot.


    \_(ツ)_/

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:21 PM
  • I am puzzled by what "remote screenshot" could mean? It sounds like a self-contradictory expression.

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:32 PM
    Moderator
  • There are tools that can be installed that will allow a remote tech to take a screenshot.  It requires a service to be installed and is used for assistance and for forensics.


    \_(ツ)_/

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:36 PM
  • Screen shot a user's RDP session, you mean? Such a tool means that there would have to be a service that knows who is logged on and be able to grab a screen image from a user's session.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:43 PM
    Moderator
  • Forensic tools can do both console a TS as well as capture video from the screen buffer.  It is used by law enforcement and legal offices to track bad guys.

    The tools, when I was looking for one, were very expensive.  $12000 and up.


    \_(ツ)_/

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:46 PM
  • The idea is to take an screenshot of the current sate of the remote server,  for example,  if the server is hanged up or the RDS service was stopped and we can't RDP into it but it is pingable, with and screen we could see if it received a black screen or if a message error just appeared. 
    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:47 PM
  • didn't know about them, thanks for the info jrv I will check them. 

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:48 PM
  • That can be easily done with ILO.  Talk to your server vendor. You can see the screen even on a fully crashed system.


    \_(ツ)_/

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:49 PM
  • ILO can also power the server up and down, read the hardware logs, replace the BIOS and configure the BIOS.  It is complete remote management for servers that are sited in impossible to get to places.  All HP, Dell and IBM servers support ILO.  It is an adapter or a daughter card that installs in the server.  It has its own Ethernet port.

    \_(ツ)_/

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:52 PM
  • Thanks, but this servers are VMs, i don't think that ILO will work with this lol, thanks anyway, i will place this as answered.

    Thanks everyone for your help.

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Monday, November 7, 2016 3:35 PM

All replies

  • That only works in a form.


    \_(ツ)_/

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 6:36 PM
  • mmm so if i create a GUI with, let say a button, and place this code on the form it will work?? lol

    If I run it locally on my pc it works

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:12 PM
  • In a remote session there is no screen so nothing can be captured.

    I have never tried to do a screenshot like that.  Yes - it might work locally without a form but not remotely.

    You can place the script on a share and have the user run it for a screenshot.


    \_(ツ)_/

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:21 PM
  • I am puzzled by what "remote screenshot" could mean? It sounds like a self-contradictory expression.

    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:32 PM
    Moderator
  • There are tools that can be installed that will allow a remote tech to take a screenshot.  It requires a service to be installed and is used for assistance and for forensics.


    \_(ツ)_/

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:36 PM
  • Screen shot a user's RDP session, you mean? Such a tool means that there would have to be a service that knows who is logged on and be able to grab a screen image from a user's session.


    -- Bill Stewart [Bill_Stewart]

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:43 PM
    Moderator
  • Forensic tools can do both console a TS as well as capture video from the screen buffer.  It is used by law enforcement and legal offices to track bad guys.

    The tools, when I was looking for one, were very expensive.  $12000 and up.


    \_(ツ)_/

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:46 PM
  • The idea is to take an screenshot of the current sate of the remote server,  for example,  if the server is hanged up or the RDS service was stopped and we can't RDP into it but it is pingable, with and screen we could see if it received a black screen or if a message error just appeared. 
    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:47 PM
  • didn't know about them, thanks for the info jrv I will check them. 

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:48 PM
  • That can be easily done with ILO.  Talk to your server vendor. You can see the screen even on a fully crashed system.


    \_(ツ)_/

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:49 PM
  • ILO can also power the server up and down, read the hardware logs, replace the BIOS and configure the BIOS.  It is complete remote management for servers that are sited in impossible to get to places.  All HP, Dell and IBM servers support ILO.  It is an adapter or a daughter card that installs in the server.  It has its own Ethernet port.

    \_(ツ)_/

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Friday, November 4, 2016 7:52 PM
  • Thanks, but this servers are VMs, i don't think that ILO will work with this lol, thanks anyway, i will place this as answered.

    Thanks everyone for your help.

    • Marked as answer by D.M.L Monday, November 7, 2016 3:35 PM
    Monday, November 7, 2016 3:35 PM