把任意文件转成vbs文件的file2vbs的vbs代码
程序员文章站
2022-04-10 08:03:33
tr4c3:为了方便在dos下使用,我把inputbox改成了args。 复制代码 代码如下:'program by xiaolu 'nam...
tr4c3:为了方便在dos下使用,我把inputbox改成了args。
复制代码 代码如下:
'program by xiaolu
'name:file2vbs.vbs
on error resume next
set args = wscript.arguments
if args.length<>2 then
wscript.echo "usage:" & wscript.scriptname & " c:\muma.exe c:\muma.vbs"
wscript.quit
end if
do while 1
fname = args(0)
set ado = createobject("adodb.stream")
with ado
.type = 1
.open
.loadfromfile fname
ss = .read
end with
exit do
loop
fname = args(1)
set fso=createobject("scripting.filesystemobject")
set file=fso.opentextfile(fname,2, true)
lens=lenb(ss) mod 500
for j=0 to int(lenb(ss)/500)-1
if j=0 then
file.writeline "ss="""&bin2str(midb(ss,500*j+1,500))&"""_"
else
file.writeline "+"""&bin2str(midb(ss,500*j+1,500))&"""_"
end if
next
if lens>0 then
file.writeline "+"""&bin2str(rightb(ss,lens))&""""
else
file.writeline "+"&chr(34)&chr(34)
end if
file.writeline ""
file.writeline "set rs=createobject(""adodb.recordset""):l=len(ss)/2:rs.fields.append ""m"",205,l:rs.open:rs.addnew:rs
(""m"")=ss&chrb(0):rs.update:ss=rs(""m"").getchunk(l)"
file.writeline "set s=createobject(""adodb.stream""):with s:.mode = 3:.type = 1:.open():.write ss:.savetofile
wscript.arguments(0),2:end with"
file.close
set fso=nothing
ado.close
set abo=nothing
function bin2str(re)
for i = 1 to lenb(re)
bt = ascb(midb(re, i, 1))
if bt < 16 then bin2str=bin2str&"0"
bin2str=bin2str & hex(bt)
next
end function
重新生成文件的办法
cscript xx.vbs x:\xxxx.exe
上一篇: Go语言实现socket实例