记录一举一动:PowerShell几行代码实现定期屏幕截屏

目录

监控电脑屏幕?

实现思路

1、通过windows脚本,一定时间间隔进行屏幕抓拍

2、脚本通过powershell语言实现

3、powershell为windows系统自带语言,可以无缝嵌入运行

4、所有抓拍的屏幕照片,按照时间排序,可以实现比较完整的用户操作监控。

PowerShell简介

如何使用PowerShell

监控屏幕脚本实现

 推荐阅读

【资源推荐】

渗透测试专用系统

渗透测试相关工具

CSDN官方学习推荐 ↓ ↓ ↓


监控电脑屏幕?

如何实现对电脑屏幕及其操作的监控?

对于屏幕的监控,一般都是针对windows操作系统

因为对于大部分Linux系统,都是无桌面状态,没有监控界面的必要。

提供一种监控靶机屏幕的解决方案及具体实现方法。

实现思路


1、通过windows脚本,一定时间间隔进行屏幕抓拍

2、脚本通过powershell语言实现

3、powershell为windows系统自带语言,可以无缝嵌入运行

4、所有抓拍的屏幕照片,按照时间排序,可以实现比较完整的用户操作监控。

实现效果如下gif:

图片

PowerShell简介

如果是从知名度和用户的使用量来谈的话,PowerShell相较当下流行的一些面向对象的语言

来说应该是逊色太多太多了,但是,作为一款系统内置的脚本语言,和Linux里的Shell一样,

说其强大当然是不容置喙的。

WindowsPowerShell是一种命令行外壳程序和脚本环境,是运行在windows机器上实现系统

和应用程序管理自动化的命令行脚本环境,使命令行用户和脚本编写者可以利用.NET

Framework的强大功能。你可以把它看成是命令行提示符cmd.exe的扩充,不对,

应当是颠覆。powershell需要.NET环境的支持,同时支持.NET对象。

微软之所以将Powershell定位为Power,并不是夸大其词,因为它完全支持对象。

其可读性,易用性,可以位居当前所有shell之首。

图片

如何使用PowerShell

  1)Win键+R,输入cmd,然后cmd会话框里再输入powershell

  2)Win键+R,输入powershell,即来到其会话框

  3)或是直接找到Windows PowerShell程序双击或是管理员打开

图片

监控屏幕脚本实现

1、执行截屏的函数

#Define helper function that generates and saves screenshot
Function Get-Screenshot {
   $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()
 }

2、将截屏图片按时间命令并按路径存储

Try {
        #load required assembly
        Add-Type -Assembly System.Windows.Forms            
        Do {
            #get the current time and build the 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 will run once regardless if the specified time as passed
        While ((Get-Date -Format HH:mm) -lt $EndTime)
    }

3、脚本执行方法

#执行命令Get-TimedScreenshot#path:指定存储路径#Interval:截屏时间间隔,单位 秒#EndTime:脚本停止时间,如果不设置,会一直执行
PS C:\> Get-TimedScreenshot -Path C:\监控截屏 -Interval 1 -EndTime 19:00

推荐阅读

【资源推荐】

python实战

【pygame开发实战开发30例 完整源码】

【pygame游戏开发专栏,获取完整源码+教程】

Supongo que te gusta

Origin blog.csdn.net/weixin_42350212/article/details/121916090
Recomendado
Clasificación