[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
本帖最后由 pcl_test 于 2017-4-30 19:48 编辑

vbs+c#.net
  1. '发送prtsc键+剪贴板获取图片,期间将清除剪贴板内容
  2. Set objShell = CreateObject("Wscript.Shell")
  3. Set fso = CreateObject("Scripting.FileSystemObject")
  4. currentpath = fso.GetFolder(".").Path '设置图片保存路径,默认为当前文件夹
  5. Set tmp = fso.GetSpecialFolder(2)
  6. Set systemroot = fso.GetSpecialFolder(0)
  7. net = systemroot&"\Microsoft.NET\Framework"
  8. If not fso.FileExists(tmp&"\$PrtSc.cs") Then
  9.     Call CreateCs
  10.     Set SubFolders = fso.GetFolder(net).SubFolders
  11.     For Each Folder In SubFolders
  12.         If fso.FileExists(Folder&"\csc.exe") Then
  13.             cscpath = Folder&"\csc.exe"
  14.             Exit For
  15.         End If
  16.     Next
  17.     If cscpath = "" Then
  18.         Msgbox "未安装Microsoft .NET Framework 2.0及以上组件或是相关程序缺失!"
  19.         Wscript.Quit
  20.     Else
  21.         '调用csc.exe编译cs文件
  22.         objShell.Run cscpath&" /out:"""&tmp&"\$PrtSc.exe"" """&tmp&"\$PrtSc.cs""", 0, True
  23.     End If
  24. End If
  25. fso.DeleteFile tmp&"\$PrtSc.cs"
  26. DO  '自行修改截屏条件
  27.     i = i + 1
  28.     objShell.Run tmp&"\$PrtSc.exe", 0, True
  29.     Wscript.Sleep 1000    '设置截屏时间间隔(毫秒)
  30. Loop Until i = 5   '设置截屏张数
  31. Function CreateCs
  32.     'C# codes,调用系统API实现截屏
  33.     Set cs = fso.CreateTextFile(tmp&"\$PrtSc.cs", True)
  34.     cs.Write _
  35.     "using System;using System.Drawing;using System.Drawing.Imaging;" & vbCrLf & _
  36.     "using System.Windows.Forms;using System.Runtime.InteropServices;" & vbCrLf & _
  37.     "public class Prtsc{" & vbCrLf & _
  38.     "   [DllImport(""user32.dll"")]" & vbCrLf & _
  39.     "   public static extern void keybd_event(byte bVk,byte bScan,uint dwFlags,IntPtr dwExtraInfo);" & vbCrLf & _
  40.     "   [STAThread]" & vbCrLf & _
  41.     "   public static void Main(){" & vbCrLf & _
  42.     "      keybd_event((byte)0x2c, 0, 0x0, IntPtr.Zero);" & vbCrLf & _
  43.     "      keybd_event((byte)0x2c, 0, 0x2, IntPtr.Zero);" & vbCrLf & _
  44.     "      string dt = System.DateTime.Now.ToString(""yyyyMMddHHmmssfff"");" & vbCrLf & _
  45.     "      IDataObject data = Clipboard.GetDataObject();" & vbCrLf & _
  46.     "      if (data.GetDataPresent(DataFormats.Bitmap)){" & vbCrLf & _
  47.     "         Image img = (Image)data.GetData(DataFormats.Bitmap,true);" & vbCrLf & _
  48.     "         img.Save("""&replace(currentpath,"\","\\")&"\\""+dt+"".bmp"", ImageFormat.Bmp);" & vbCrLf & _
  49.     "}}}"
  50. End Function
复制代码
  1. '参考http://www.bathome.net/redirect.php?goto=findpost&pid=78571&ptid=11646
  2. '期间不影响剪贴板内容
  3. Set objShell = CreateObject("Wscript.Shell")
  4. Set fso = CreateObject("Scripting.FileSystemObject")
  5. currentpath = fso.GetFolder(".").Path '设置图片保存路径,默认为当前文件夹
  6. Set tmp = fso.GetSpecialFolder(2)
  7. Set systemroot = fso.GetSpecialFolder(0)
  8. net = systemroot&"\Microsoft.NET\Framework"
  9. If not fso.FileExists(tmp&"\$PrtSc.cs") Then
  10.     Call CreateCs
  11.     Set SubFolders = fso.GetFolder(net).SubFolders
  12.     For Each Folder In SubFolders
  13.         If fso.FileExists(Folder&"\csc.exe") Then
  14.             cscpath = Folder&"\csc.exe"
  15.             Exit For
  16.         End If
  17.     Next
  18.     If cscpath = "" Then
  19.         Msgbox "未安装Microsoft .NET Framework 2.0及以上组件或是相关程序缺失!"
  20.         Wscript.Quit
  21.     Else
  22.         '调用csc.exe编译cs文件
  23.         objShell.Run cscpath&" /out:"""&tmp&"\$PrtSc.exe"" """&tmp&"\$PrtSc.cs""", 0, True
  24.     End If
  25. End If
  26. fso.DeleteFile tmp&"\$PrtSc.cs"
  27. DO  '自行修改截屏条件
  28.     i = i + 1
  29.     objShell.Run tmp&"\$PrtSc.exe", 0, True
  30.     Wscript.Sleep 1000    '设置截屏时间间隔(毫秒)
  31. Loop Until i = 5   '设置截屏张数
  32. Function CreateCs
  33.     Set cs = fso.CreateTextFile(tmp&"\$PrtSc.cs", True)
  34.     cs.Write _
  35.     "using System;using System.Drawing;using System.Drawing.Imaging;using System.Windows.Forms;" & vbCrLf & _
  36.     "public class Prtsc{" & vbCrLf & _
  37.     "   public static void Main(){" & vbCrLf & _
  38.     "       Image img = new Bitmap(Screen.AllScreens[0].Bounds.Width, Screen.AllScreens[0].Bounds.Height);" & vbCrLf & _
  39.     "       Graphics g = Graphics.FromImage(img);" & vbCrLf & _
  40.     "       g.CopyFromScreen(new Point(0, 0), new Point(0, 0), Screen.AllScreens[0].Bounds.Size);" & vbCrLf & _
  41.     "       string dt = System.DateTime.Now.ToString(""yyyyMMddHHmmssfff"");" & vbCrLf & _
  42.     "       img.Save("""&replace(currentpath,"\","\\")&"\\""+dt+"".bmp"", ImageFormat.Bmp);" & vbCrLf & _
  43.     "}}"
  44. End Function
复制代码
3

评分人数

TOP

返回列表