中国DOS联盟论坛

中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net  论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

游客:  注册 | 登录 | 命令行 | 会员 | 搜索 | 上传 | 帮助 »
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 用VBS脚本实现截屏到系统剪贴板或画图
« [1] [2] »
作者:
标题: 用VBS脚本实现截屏到系统剪贴板或画图 上一主题 | 下一主题
my3439955
中级用户




积分 272
发帖 99
注册 2006-6-2
状态 离线
『楼 主』:  用VBS脚本实现截屏到系统剪贴板或画图

这样把简短的第三方工具集合到VBS脚本中就可以实现更丰富的功能了

本帖还可以作为在VBS中嵌入二进制代码的通用方法
data = "4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000C00000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000450E6EDA016F0089016F0089016F0089016F0189006F008963701389026F0089E9700B89006F008952696368016F008900000000000000000000000000000000504500004C01010017E773460000000000000000E0000F010B01060000000000000400000000000080110000001000000010000000004000001000000002000004000000000000000400000000000000002000000002000000000000020000000000100000100000000010000010000000000000100000000000000000000000F012000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000080000000000000000000000000000000000000000000000000000002E646174610000003A030000001000000004000000020000000000000000000000000000400000C0000000000000000000000000000000000000000000000000000000000000000020130000000000004D657373616765426F784100476574436F6D6D616E644C696E6541006B657962645F6576656E74004578697450726F6365737300467265654C696272617279004C6F61644C6962726172794100000000757365723332000053637265656E4361746368204279205368696C7978000000B3C9B9A6BDABD7A5CDBCB1A3B4E6B5BDCFB5CDB3BCF4CCF9B0E5000000000000000000000000000083EC0C535556578B7C24208B473C03C78138504500000F858E0000008B48788B44392003CF03C7894C2418C7442420000000008B491885C9894C2414766C8B6C2424894424248A4D008BD181E2FF00000089542410EB048B5424108B008BCD8D343833C08A062BC275248A55002BF584D274178A51014133C08BDA8A040E81E3FF0000002BC374E7EB0485C074268B4C24208B4424248B5424144183C0043BCA894C24208944242472AD5F5E5D33C05B83C40CC38B4424188B5424208B48248B401C8D0C5133D2668B14398D0C908B043903C75F5E5D5B83C40CC39090909090558BEC81EC48010000535657B906000000BE781040008D7DBCF3A566A5A4B905000000BE601040008D7DD8A158104000F3A5668B0D5C1040008A155E10400066A58945F466894DF88855FAC745FC0000000064A1180000008945FC8B45FC68481040008B48308B510C8B420C8B088B118B721856E8A7FEFFFF683C104000568BF8E89AFEFFFF6830104000568945FCE88CFEFFFF83C4188945F08D45F450FFD78BD8682410400053E873FEFFFF8B3D0010400083C4086A006A006A006A2CFFD76A006A026A006A2CFFD7681410400056E84BFEFFFF8BD0B94000000033C08DBDB9FEFFFFC685B8FEFFFF0083C408F3AB66ABAAFFD28BF883C9FF33C08D95B8FEFFFFF2AEF7D12BF98BC18BF78BFAC1E902F3A58BC833C083E103F3A48DBDB8FEFFFF83C9FFF2AEF7D1498A8C0DB7FEFFFF80F973742180F953741C680810400053E8DAFDFFFF83C4088D4DD88D55BC6A4051526A00FFD053FF55FC6A00FF55F05F5E5B8BE55DC39090909090909090901813000000000000000000002E1300000010000000000000000000000000000000000000000000002013000000000000AA026B657962645F6576656E74005553455233322E646C6C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"

TargetFileName = "C:\tmp.exe"

With CreateObject("ADODB.Stream"):.Type = 1:.Open:.Write StrToByte(data):.SaveToFile TargetFileName, 2:.Close:End With

WScript.CreateObject("WScript.Shell").Run TargetFileName & " /s"
MsgBox "当前屏幕图象已经拷贝到系统剪贴板", 64, "信息"

Function StrToByte(str)
        Set xmldoc = CreateObject("Microsoft.XMLDOM")
        xmldoc.loadXML "<?xml version=""1.0""?>"
        Set pic = xmldoc.createElement("pic")
        pic.dataType = "bin.hex"
        pic.nodeTypedValue = str
        StrToByte = pic.nodeTypedValue
End Function
十二楼的代码增加了对发送到画图的支持

[ Last edited by my3439955 on 2007-6-18 at 07:12 PM ]

   此帖被 +25 点积分      点击查看详情   
评分人:【 lxmxn 分数: +8  时间:2007-6-16 21:52
评分人:【 wudixin96 分数: +8  时间:2007-6-16 22:04
评分人:【 zh159 分数: +9  时间:2007-6-16 23:24




X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
2007-6-16 21:48
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
lxmxn
版主




积分 11386
发帖 4938
注册 2006-7-23
状态 离线
『第 2 楼』:  

这个不错啊,加分鼓励一下。

2007-6-16 21:51
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
wudixin96
银牌会员





积分 1928
发帖 931
注册 2007-1-6
状态 离线
『第 3 楼』:  

还用到XML。不错。加分,:-)

2007-6-16 22:01
查看资料  发短消息 网志   编辑帖子  回复  引用回复
my3439955
中级用户




积分 272
发帖 99
注册 2006-6-2
状态 离线
『第 4 楼』:  

不这样的话写不了二进制文件呀



X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
2007-6-16 22:05
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
zh159
金牌会员




积分 3687
发帖 1467
注册 2005-8-8
状态 离线
『第 5 楼』:  

越大的二进制文件感觉用baomaboy的“转为批处理文件”转换出来越省空间(小文件主要是写入部分脚本较多)

LZ的是3.57k,这个是3.1k
bs=_
"NpFkAMAAAAABAAAA//PAAgLAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADA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wOKnITkASiERCJy16Xe11MAv1gEzwwLSEJYsIVkAyiIRyiAxRjME1MSb2iUkTjMA5iEkzAH/lXdt1gEzwwQCJkQCZVLyegsjUA"+_
"AAwUWdVuGAAAA4LeQAEAN2HvzXqZlSauFAAAA4LYQAEAN2H2hiFEABw8la2iNwFEABgiV4FEABgZlmYR0bWiNhPiVp/xFxPAAAAAkFKGAAAAJWE/LWE/ohEEABwiIBziRxwiCxwiIsYELKHGWh+p+///oxDEABgVLiP6a6///jGM"+_
"QAEAWlYR8jOj+///DSMGJWE8NWE9Q9/1LiNakABQAMF6z5///vYPAABQAMIxIoGAqBgaAoGL/ftaAomAqBgas8/1oRBEABgVovk////iQnLQAAAAzAcj9mr///vxFir///PADSMCzvqZrq6/SvI+Dm8/zAcjVir///v8uef0rk/i"+_
"Bv49LqfwpLw8luIyzA8ghPw8k2Yv46///PYy/Lvr3HdSKyYD36///DY+zRXIAm/U0xBaIABQAMF6a3///PIxI0YTY3YV8qGQRJlaA8P0T9fV8rGA/XF8f51WLWeXDDJkQCJkQCJkQixEAAAAAAAAAAAAA4yEAAAAQAAAAAAAAAAA"+_
"AAAAAAAAAAAAAAAAAAAITAAAAAAAAoqArVWeiR2XlZXZuRHAVNVRSNjMuQGbsBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"+_
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"+_
"":set rs=CreateObject("ADODB.Recordset")
set ado=CreateObject("ADODB.Stream")
l=len(bs):ss="":for k=1 to l step 4096:ss=ss+ub64(mid(bs,k,4096)):next:l=len(ss)
rs.fields.append "b",205,l/2:rs.open:rs.addnew:rs("b")=ss+chrb(0):rs.update
ado.mode=3:ado.type=1:ado.open:ado.write rs("b").getchunk(l/2)
ado.savetofile "tmp.exe",2:ado.close

WScript.CreateObject("WScript.Shell").Run "tmp.exe /s"
MsgBox "当前屏幕图象已经拷贝到系统剪贴板", 64, "信息"

function ub64(s):dim t(4),b(3):ub64="":n=len(s):r=2
if n mod 4<>0 then exit function:end if:for i=1 to n step 4:for j=0 to 3
a=asc(mid(s,i+j,1)):if a=43 then:a=62:else if a=47 then:a=63:else if a>47 and a<58 then:_
a=a+4:else if a=61 then:a=0:if r=2 then r=j-2:end if:else if a>64 and a<91 then:_
a=a-65:else if a>96 and a<123 then:a=a-71:else:exit function:_
end if:end if:end if:end if:end if:end if:t(j)=a:next
b(0)=t(0)+t(1)*64 mod 256:b(1)=t(1)\4+t(2)*16 mod 256:b(2)=t(2)\16+t(3)*4
for j=0 to r:if b(j)<16 then ub64=ub64+"0":end if:ub64=ub64+hex(b(j))
next:next:end function
[ Last edited by zh159 on 2007-6-16 at 11:05 PM ]



2007-6-16 23:04
查看资料  发短消息 网志   编辑帖子  回复  引用回复
my3439955
中级用户




积分 272
发帖 99
注册 2006-6-2
状态 离线
『第 6 楼』:  

对的
这个使用的字符集比我的多得多
因此压缩率方面肯定占优势



X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
2007-6-16 23:06
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
zh159
金牌会员




积分 3687
发帖 1467
注册 2005-8-8
状态 离线
『第 7 楼』:  

你这个的好处是可以将16进制数据直接写入bin;之前刚用过,将GB文字转为16进制的UTF-8编码写为BIN文件



2007-6-16 23:14
查看资料  发短消息 网志   编辑帖子  回复  引用回复
eech
高级用户




积分 906
发帖 346
注册 2006-7-10
状态 离线
『第 8 楼』:  

太好了,问了这么久,终于有结果了,可以改一下,将抓到的图直接发送到画图中吗?这样就方便多了,不知要求是不是太过分了,呵呵

2007-6-16 23:39
查看资料  发短消息 网志   编辑帖子  回复  引用回复
eech
高级用户




积分 906
发帖 346
注册 2006-7-10
状态 离线
『第 9 楼』:  

再加一句删除生成临时文件的代码不好吗?用的时候再生成是了

2007-6-16 23:49
查看资料  发短消息 网志   编辑帖子  回复  引用回复
my3439955
中级用户




积分 272
发帖 99
注册 2006-6-2
状态 离线
『第 10 楼』:  

这是纯API写的程序

能小到1.5K已经很不容易了

要支持图象保存的话程序会异常烦琐

使用类库比较简单

但是目标程序又非常大

两难啊



X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
2007-6-16 23:53
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
my3439955
中级用户




积分 272
发帖 99
注册 2006-6-2
状态 离线
『第 11 楼』:  



  Quote:
Originally posted by eech at 2007-6-16 23:49:
再加一句删除生成临时文件的代码不好吗?用的时候再生成是了


是不错
可是很多时候那个程序回弹出一个通知对话框
程序在内存驻留
是删不掉的



X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
2007-6-16 23:57
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
my3439955
中级用户




积分 272
发帖 99
注册 2006-6-2
状态 离线
『第 12 楼』:  

现在可以支持发送到画图了

以下脚本生成的Exe文件加/c参数可以达到发送到画图的功能
Data = "4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000C00000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000450E6EDA016F0089016F0089016F0089016F0189006F008963701389026F0089E9700B89006F008952696368016F008900000000000000000000000000000000504500004C010100E61174460000000000000000E0000F010B010600000000000004000000000000C0110000001000000010000000004000001000000002000004000000000000000400000000000000002000000002000000000000020000000000100000100000000010000010000000000000100000000000000000000000B013000028000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000080000000000000000000000000000000000000000000000000000002E64617461000000FA030000001000000004000000020000000000000000000000000000400000C00000000000000000000000000000000000000000000000000000000000000000E0130000000000006D737061696E74004D535061696E744170700000536C65657000000057696E4578656300506F73744D657373616765410000000046696E6457696E646F7741004D657373616765426F784100476574436F6D6D616E644C696E6541006B657962645F6576656E74004578697450726F6365737300467265654C696272617279004C6F61644C6962726172794100000000757365723332000053637265656E4361746368204279205368696C7978000000B3C9B9A6BDABD7A5CDBCB1A3B4E6B5BDCFB5CDB3BCF4CCF9B0E5000000000000000000000000000083EC0C535556578B7C24208B473C03C78138504500000F858E0000008B48788B44392003CF03C7894C2418C7442420000000008B491885C9894C2414766C8B6C2424894424248A4D008BD181E2FF00000089542410EB048B5424108B008BCD8D343833C08A062BC275248A55002BF584D274178A51014133C08BDA8A040E81E3FF0000002BC374E7EB0485C074268B4C24208B4424248B5424144183C0043BCA894C24208944242472AD5F5E5D33C05B83C40CC38B4424188B5424208B48248B401C8D0C5133D2668B14398D0C908B043903C75F5E5D5B83C40CC39090909090558BEC83EC50535657B906000000BEB81040008D7DB0F3A566A5A4B905000000BEA01040008D7DCCA198104000F3A5668B0D9C1040008A159E10400066A58945E466894DE88855EAC745FC0000000064A1180000008945FC8B45FC68881040008B48308B510C8B420C8B088B118B5A1853E8AAFEFFFF687C104000538BF0E89DFEFFFF6870104000538945F0E88FFEFFFF83C4188945EC8D45E450FFD66864104000508945FCE875FEFFFF8B350010400083C4086A006A006A006A2CFFD66A006A026A006A2CFFD6685410400053E84DFEFFFF33C983C408894DF58BF0C645F40066894DF9FFD68BF883C9FF33C0F2AEF7D1498BF9FFD68D7C07FB8D55F483C9FF33C0F2AEF7D12BF98BC18BF78BFAC1E902F3A58BC833C083E103F3A48D7DF483C9FFF2AEF7D1498A4C0DF380F963743880F943743380F9730F849C00000080F9530F84930000008B4DFC684810400051E8CAFDFFFF83C4088D55CC8D4DB06A4052516A00FFD0EB728B7DFC683C10400057E8A9FDFFFF682C104000578BF0E89CFDFFFF6824104000538945F4E88EFDFFFF681C104000538BF8E881FDFFFF83C4208BD86A006810104000FFD685C0751A6A016808104000FFD76A0AFFD36A006810104000FFD685C074EF6A006825E10000681101000050FF55F48B55FC52FF55F06A00FF55EC5F5E5B8BE55DC39090D81300000000000000000000EE130000001000000000000000000000000000000000000000000000E013000000000000AA026B657962645F6576656E74005553455233322E646C6C0000000000000000"

With CreateObject("ADODB.Stream"):.Type = 1:.Open:.Write StrToByte(data):.SaveToFile GetTargetFileName, 2:.Close:End With

Function GetTargetFileName
    Set objDialog = CreateObject("UserAccounts.CommonDialog")
    objDialog.Filter = "All Files|*.*"
    objDialog.InitialDir = "."
    If objDialog.ShowOpen = 0 Then
        WScript.Quit
    Else
        GetTargetFileName = objDialog.FileName
    End If
    Set objDialog = Nothing
End Function

Function StrToByte(str)
        Set xmldoc = CreateObject("Microsoft.XMLDOM")
        xmldoc.loadXML "<?xml version=""1.0""?>"
        Set pic = xmldoc.createElement("pic")
        pic.dataType = "bin.hex"
        pic.nodeTypedValue = str
        StrToByte = pic.nodeTypedValue
End Function
查看如何使用这种类型的VBS脚本

[ Last edited by my3439955 on 2007-6-17 at 06:49 PM ]



X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
2007-6-17 00:44
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
zh159
金牌会员




积分 3687
发帖 1467
注册 2005-8-8
状态 离线
『第 13 楼』:  

改一下就可以删除临时文件
WScript.CreateObject("WScript.Shell").Run TargetFileName & " /s",,true
WScript.CreateObject("WScript.Shell").Run "cmd /c del " &TargetFileName,vbhid
MsgBox "当前屏幕图象已经拷贝到系统剪贴板", 64, "信息"




2007-6-17 01:15
查看资料  发短消息 网志   编辑帖子  回复  引用回复
my3439955
中级用户




积分 272
发帖 99
注册 2006-6-2
状态 离线
『第 14 楼』:  

会不会程序还没来得及启动就已经被删除了?



X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
2007-6-17 11:54
查看资料  发送邮件  发短消息 网志   编辑帖子  回复  引用回复
zh159
金牌会员




积分 3687
发帖 1467
注册 2005-8-8
状态 离线
『第 15 楼』:  



  Quote:
Originally posted by my3439955 at 2007-6-17 11:54:
会不会程序还没来得及启动就已经被删除了?

我试过了,可以抓屏,你也可以试试
关键在于WScript.CreateObject("WScript.Shell").Run TargetFileName & " /s",,true,使用true必需要运行的程序执行完毕才进入下一步
PS:需要两个逗号,因为第一个逗号段可以增加vbhid使用,作为隐藏运行



2007-6-17 13:51
查看资料  发短消息 网志   编辑帖子  回复  引用回复
« [1] [2] »
请注意:您目前尚未注册或登录,请您注册登录以使用论坛的各项功能,例如发表和回复帖子等。


可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题



论坛跳转: