当前位置:编程学习 > VB >>

新版Any2Bat.vbs

作者:zzzEVAzzz

作用是把任何文件变成echo版,以便通过远程上传。

新版本改进如下:
1,增加数据压缩功能(使用系统自带的makecab.exe和expand.exe)。
2,Base64编码采用Microsoft.XMLDOM,速度快,代码更简洁。
3,echo生成临时脚本时文件名不带后缀,避免杀毒软件频繁扫描,提高效率。

Any2Bat.vbs v2.0 by zzzEVAzzz
Set fso = CreateObject("Scripting.FileSystemObject")
Set shl = CreateObject("WScript.Shell")
Set xml = CreateObject("Microsoft.XMLDOM")
Set stm = CreateObject("ADODB.Stream")

Set arg = WScript.Arguments
If arg.Count = 0 Then WScript.Quit
If Not fso.FileExists(arg(0)) Then WScript.Quit

Set f = fso.GetFile(arg(0))
rr = shl.Run("makecab.exe """ & f.Path & """ """ & f.Name & ".cab""", 0, True)
If rr <> 0 Then WScript.Quit

Set el = xml.createElement("tmp")
el.dataType = "bin.base64"
stm.Open : stm.Type = 1
stm.LoadFromFile f.Name & ".cab"
el.nodeTypedValue = stm.Read
txt = Replace(el.text, vbLf, ">>xx" & vbNewLine & "@echo ")
stm.Close
fso.DeleteFile f.Name & ".cab"

With fso.OpenTextFile(f.Path & ".bat", 2, True)
.WriteLine "@echo ^<package^>^<cab xmlns:dt=""urn:schemas-microsoft-com:datatypes"" dt:dt=""bin.base64""^> >xx"
.Write "@echo " : .Write txt : .WriteLine ">>xx"
.WriteLine "@echo ^</cab^>^<job^>^<script language=""VBScript""^> >>xx"
.WriteLine "@echo Set xml = CreateObject(""Microsoft.XMLDOM"")>>xx"
.WriteLine "@echo xml.load WScript.ScriptFullName>>xx"
.WriteLine "@echo Set stm = CreateObject(""ADODB.Stream"")>>xx"
.WriteLine "@echo stm.Open : stm.Type = 1 >>xx"
.WriteLine "@echo stm.Write xml.documentElement.childNodes.item(0).nodeTypedValue>>xx"
.WriteLine "@echo stm.SaveToFile ""xx.cab"">>xx"
.WriteLine "@echo ^</script^>^</job^>^</package^> >>xx"
.WriteLine "rename xx xx.wsf"
.WriteLine "cscript.exe //nologo xx.wsf"
.WriteLine "expand.exe -r xx.cab>nul"
.Write "del xx.wsf & del xx.cab"
.Close
End With

用法不变。以文件名为参数,或拖放文件到Any2Bat.vbs的图标上。
文件大小以生成的bat不超过500K为宜。

补充:综合编程 , 其他综合 ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,