标题: [问题求助] xp或win7系统下,VBS如何实现循环间歇性屏幕截图并以指定格式命名保存到指定目录下 [打印本页]
作者: ygqiang 时间: 2016-8-2 06:17 标题: xp或win7系统下,VBS如何实现循环间歇性屏幕截图并以指定格式命名保存到指定目录下
本帖最后由 pcl_test 于 2016-8-2 12:22 编辑
xp或win7系统环境下,VBS定时截屏,并保存到指定目录下。如何实现?
比如定时3秒钟全屏截屏,所有截屏文件全部保存到c:\test目录下。
文件名中命名规则是:20160802-061840(年代日期-时间)
设置变量:jiang(以秒计数)
设置变量:mulu(截屏图片保存目录)
截屏代码参考
http://www.bathome.net/redirect. ... 4369&ptid=37237
作者: yu2n 时间: 2016-8-2 22:16
推荐使用第三方命令行截图软件。
CmdCapture 命令行截图软件:http://www.bathome.net/thread-41237-1-1.html
作者: pcl_test 时间: 2016-8-3 14:12
本帖最后由 pcl_test 于 2017-4-16 19:48 编辑
- Set ws = CreateObject("Wscript.Shell")
- Set dict = WSH.CreateObject("Scripting.Dictionary")
- Set fso = CreateObject("Scripting.FileSystemObject")
-
- dstFolder = "." '指定截图保存目录,默认为当前目录下
- ext = "jpg" '指定截图文件格式,支持jpg/gif/png/bmp
- interval = 1000 '指定截屏间歇时间(毫秒)
-
- If Left(ext, 1) = "." Then ext = Right(ext, 3)
- If Right(dstFolder, 1) <> "\" Then dstFolder=dstFolder&"\"
- arr = Split(dstFolder, "\")
- arrFolder = arr(0)
- For i = 1 To UBound(arr) -1
- arrFolder = arrFolder & "\" & arr(i)
- If Not fso.FolderExists(arrFolder) Then fso.CreateFolder(arrFolder)
- Next
-
- dict.Add "jpg", "ImageFormat.Jpeg"
- dict.Add "gif", "ImageFormat.Gif"
- dict.Add "png", "ImageFormat.Png"
- dict.Add "bmp", "ImageFormat.Bmp"
-
- Set tmp = fso.GetSpecialFolder(2)
- Set systemroot = fso.GetSpecialFolder(0)
- net = systemroot&"\Microsoft.NET\Framework"
- Call CreateCs
- Set SubFolders = fso.GetFolder(net).SubFolders
- For Each Folder In SubFolders
- If fso.FileExists(Folder&"\csc.exe") Then
- cscpath = Folder&"\csc.exe"
- Exit For
- End If
- Next
-
- If cscpath = "" Then
- Msgbox "未安装Microsoft .NET Framework 2.0及以上版本组件或是相关程序缺失!"
- WSH.Quit
- Else
- '调用csc.exe编译cs文件
- ws.Run cscpath&" /out:"""&tmp&"\$PrtSc.exe"" """&tmp&"\$PrtSc.cs""", 0, True
- End If
-
- Do
- ws.Run tmp&"\$PrtSc.exe", 0, True '执行截屏
- WSH.Sleep interval
- Loop '退出程序需从任务管理器结束wscript.exe进程
-
- Function CreateCs
- Set cs = fso.CreateTextFile(tmp&"\$PrtSc.cs", 2)
- cs.Write _
- "using System.Drawing;using System.Drawing.Imaging;using System.Windows.Forms;" & vbCrLf & _
- "public class MyClass{" & vbCrLf & _
- " public static void Main(){" & vbCrLf & _
- " Image img = new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height);" & vbCrLf & _
- " Graphics g = Graphics.FromImage(img);" & vbCrLf & _
- " g.CopyFromScreen(new Point(0, 0), new Point(0, 0), Screen.AllScreens[0].Bounds.Size);" & vbCrLf & _
- " string dt = System.DateTime.Now.ToString(""yyyyMMddHHmmss-fff"");" & vbCrLf & _
- " img.Save("""&replace(fso.GetFolder(dstFolder).Path,"\","\\")&"\\""+dt+""."&Lcase(ext)&""", "&dict.Item(Lcase(ext))&");}}"
- End Function
复制代码
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |