本帖最后由 pcl_test 于 2017-4-30 19:48 编辑
vbs+c#.net- '发送prtsc键+剪贴板获取图片,期间将清除剪贴板内容
- Set objShell = CreateObject("Wscript.Shell")
- Set fso = CreateObject("Scripting.FileSystemObject")
- currentpath = fso.GetFolder(".").Path '设置图片保存路径,默认为当前文件夹
- Set tmp = fso.GetSpecialFolder(2)
- Set systemroot = fso.GetSpecialFolder(0)
- net = systemroot&"\Microsoft.NET\Framework"
- If not fso.FileExists(tmp&"\$PrtSc.cs") Then
- 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及以上组件或是相关程序缺失!"
- Wscript.Quit
- Else
- '调用csc.exe编译cs文件
- objShell.Run cscpath&" /out:"""&tmp&"\$PrtSc.exe"" """&tmp&"\$PrtSc.cs""", 0, True
- End If
- End If
- fso.DeleteFile tmp&"\$PrtSc.cs"
- DO '自行修改截屏条件
- i = i + 1
- objShell.Run tmp&"\$PrtSc.exe", 0, True
- Wscript.Sleep 1000 '设置截屏时间间隔(毫秒)
- Loop Until i = 5 '设置截屏张数
-
- Function CreateCs
- 'C# codes,调用系统API实现截屏
- Set cs = fso.CreateTextFile(tmp&"\$PrtSc.cs", True)
- cs.Write _
- "using System;using System.Drawing;using System.Drawing.Imaging;" & vbCrLf & _
- "using System.Windows.Forms;using System.Runtime.InteropServices;" & vbCrLf & _
- "public class Prtsc{" & vbCrLf & _
- " [DllImport(""user32.dll"")]" & vbCrLf & _
- " public static extern void keybd_event(byte bVk,byte bScan,uint dwFlags,IntPtr dwExtraInfo);" & vbCrLf & _
- " [STAThread]" & vbCrLf & _
- " public static void Main(){" & vbCrLf & _
- " keybd_event((byte)0x2c, 0, 0x0, IntPtr.Zero);" & vbCrLf & _
- " keybd_event((byte)0x2c, 0, 0x2, IntPtr.Zero);" & vbCrLf & _
- " string dt = System.DateTime.Now.ToString(""yyyyMMddHHmmssfff"");" & vbCrLf & _
- " IDataObject data = Clipboard.GetDataObject();" & vbCrLf & _
- " if (data.GetDataPresent(DataFormats.Bitmap)){" & vbCrLf & _
- " Image img = (Image)data.GetData(DataFormats.Bitmap,true);" & vbCrLf & _
- " img.Save("""&replace(currentpath,"\","\\")&"\\""+dt+"".bmp"", ImageFormat.Bmp);" & vbCrLf & _
- "}}}"
- End Function
复制代码
- '参考http://www.bathome.net/redirect.php?goto=findpost&pid=78571&ptid=11646
- '期间不影响剪贴板内容
- Set objShell = CreateObject("Wscript.Shell")
- Set fso = CreateObject("Scripting.FileSystemObject")
- currentpath = fso.GetFolder(".").Path '设置图片保存路径,默认为当前文件夹
- Set tmp = fso.GetSpecialFolder(2)
- Set systemroot = fso.GetSpecialFolder(0)
- net = systemroot&"\Microsoft.NET\Framework"
- If not fso.FileExists(tmp&"\$PrtSc.cs") Then
- 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及以上组件或是相关程序缺失!"
- Wscript.Quit
- Else
- '调用csc.exe编译cs文件
- objShell.Run cscpath&" /out:"""&tmp&"\$PrtSc.exe"" """&tmp&"\$PrtSc.cs""", 0, True
- End If
- End If
- fso.DeleteFile tmp&"\$PrtSc.cs"
- DO '自行修改截屏条件
- i = i + 1
- objShell.Run tmp&"\$PrtSc.exe", 0, True
- Wscript.Sleep 1000 '设置截屏时间间隔(毫秒)
- Loop Until i = 5 '设置截屏张数
-
- Function CreateCs
- Set cs = fso.CreateTextFile(tmp&"\$PrtSc.cs", True)
- cs.Write _
- "using System;using System.Drawing;using System.Drawing.Imaging;using System.Windows.Forms;" & vbCrLf & _
- "public class Prtsc{" & 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(""yyyyMMddHHmmssfff"");" & vbCrLf & _
- " img.Save("""&replace(currentpath,"\","\\")&"\\""+dt+"".bmp"", ImageFormat.Bmp);" & vbCrLf & _
- "}}"
- End Function
复制代码
|