屏幕定时截屏并保存图像(bat+powershell+c#实现)
求大神帮编程,然后我复制进 记事本 改后缀名成bat就能用 运行一次就帮我截今天的屏
设定7:00 截屏一次 8:00截屏一次 以此类推 截屏到23:00 每个小时截屏一次 并以时间为名字命名保存在C:\Users\Public\Pictures
越简单越好
谢谢!
cmd 怎么截屏 截屏命令是什么?
---------------------------------------------------------------------------------------
复制粘贴到记事本,另存为xx.bat,编码选ANSI<# : cls @echo off rem 整点自动截屏 mode con cols=40 lines=8 if "%~1" equ "" ( start /min "" "%~f0" fk exit ) cd /d "%~dp0" powershell -sta -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default)))" pause exit #> #截屏图片存放的目录 $folder="C:\ScreenShot"; if(-not (test-path -liter $folder)){[void](md $folder)}; $codes=@' using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms; public static class ScreenShot{ public static void Save(string f){ Image img=new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height); Graphics g=Graphics.FromImage(img); g.CopyFromScreen(new Point(0, 0), new Point(0, 0), Screen.AllScreens[0].Bounds.Size); img.Save(f, ImageFormat.Bmp); } } '@; Add-Type -TypeDefinition $codes -ReferencedAssemblies 'System.Windows.Forms','System.Drawing'; $n=0;while($true){ cls $now=(get-date).toString('yyyy-MM-dd HH:mm:ss'); write-host 'Keep this window minimized'; write-host 'Do not close this window'; write-host $n.toString();write-host $now; $m=[regex]::match($now, '00:0[0-9]$'); if($m.Success){ $newfile=$folder.trimend('\')+'\'+($now -replace '[-\s:]|\d\d$','')+'00.bmp'; if(-not (test-path -liter $newfile)){$n++;[ScreenShot]::Save($newfile);}; }; start-sleep -Seconds 1; }
===============================================================
个人使用
1)调整一下换行,增加了一些注释
<# : cls @echo off rem 整点自动截屏 mode con cols=40 lines=8 if "%~1" equ "" ( start /min "" "%~f0" fk exit ) cd /d "%~dp0" powershell -sta -NoProfile -ExecutionPolicy bypass "Invoke-Command -ScriptBlock ([ScriptBlock]::Create([IO.File]::ReadAllText('%~f0',[Text.Encoding]::Default)))" pause exit #> #截屏图片存放的目录 $folder="D:\ScreenShot"; if(-not (test-path -liter $folder)){[void](md $folder)}; $codes=@' using System.Drawing; using System.Drawing.Imaging; using System.Windows.Forms; public static class ScreenShot{ public static void Save(string f){ Image img=new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height); Graphics g=Graphics.FromImage(img); g.CopyFromScreen(new Point(0, 0), new Point(0, 0), Screen.AllScreens[0].Bounds.Size); img.Save(f, ImageFormat.Bmp); } } '@; Add-Type -TypeDefinition $codes -ReferencedAssemblies 'System.Windows.Forms','System.Drawing'; $n=0; #不需要循环,可以把while去掉,只保留方法体 while($true){ cls $now=(get-date).toString('yyyy-MM-dd HH:mm:ss'); write-host 'Keep this window minimized'; write-host 'Do not close this window'; write-host 'ScreenShot count:'$n.toString(); write-host $now; #使用正则匹配正点时间 $m=[regex]::match($now, '17:00:0[0-9]$');#下面的判断可以使用$True,或者$m.Success if($m.Success){ $newfile=$folder.trimend('\')+'\'+($now -replace '[-\s:]|\d\d$','')+'00.bmp'; $newfile=$folder.trimend('\')+'\'+($now -replace '[-\s:]','')+'.bmp'; if(-not (test-path -liter $newfile)){$n++;[ScreenShot]::Save($newfile);}; }; start-sleep -Seconds 1; }
出处:https://zhidao.baidu.com/question/1515575716199249700.html
如果,您希望更容易地发现我的新博客,不妨点击一下绿色通道的【关注我】。(●'◡'●)
因为,我的写作热情也离不开您的肯定与支持,感谢您的阅读,我是【Jack_孟】!
本文来自博客园,作者:jack_Meng,转载请注明原文链接:https://www.cnblogs.com/mq0036/p/19200048
【免责声明】本文来自源于网络,如涉及版权或侵权问题,请及时联系我们,我们将第一时间删除或更改!
浙公网安备 33010602011771号