当前位置: 移动技术网 > IT编程>脚本编程>VBScript > 可以将Bat转换位VBS文件的VBS脚本

可以将Bat转换位VBS文件的VBS脚本

2017年12月12日  | 移动技术网IT编程  | 我要评论

哈牛网,晏劭廷,七匹狼男装网购

下面代码稍有修改,原结构是脚本与释放的bat同步执行并等待bat执行完毕后删除bat,本意是不遗留临时文件。后来想想通用性不好,比如释放执行的bat文件是个常驻进程的监视类型那vbs也会无休止的等待而无法退出,所以还是改为异步执行,脚本调用bat后自行退出。考虑到还原原文件的完整性末尾添加自删除也打消了想法。压缩包暂未更新。
复制代码 代码如下:

'bat2vbs.vbs by baomaboy
dim wshshell,fso
on error resume next
set wshshell = wscript.createobject("wscript.shell")
set fso = createobject("scripting.filesystemobject")
set winver = wshshell.environment("process")
set args = wscript.arguments
closetime = 5
filename = wscript.scriptname
filefullname = wscript.scriptfullname
filepath = fso.getparentfoldername(filefullname)
inspath = fso.getspecialfolder(1)
insfullname = fso.buildpath(inspath ,filename)
lnkpathnt = wshshell.specialfolders(2)
lnkpath9x = wshshell.specialfolders(14)
lnkpathall = wshshell.specialfolders("sendto")
otherfilename="manage_new.txt"
otherfilepath=fso.getspecialfolder(2)
temfilename="无标题"
temfilepath=fso.getspecialfolder(2)
copyright="玲珑科技"
qq="qq:25926183"
email="email:fty1995@163.com"
institle="bat2vbs by baomaboy"
insanswer="bat2vbs by baomaboy"
regpath1="hkey_classes_root\batfile\shell\battovbs\"
regvalue1="bat转vbs脚本文件"
regform1="reg_sz"
regpath2="hkey_classes_root\batfile\shell\battovbs\command\"
regvalue2="wscript.exe " & chr(34) & insfullname & chr(34) & " " & chr(34) & "%l" & chr(34)
regform2="reg_sz"
if filefullname <> insfullname then
intanswer = msgbox("【是】将“"+ insanswer +"”加入到右键菜单,"&chr(10)&chr(10)&"【否】将“"+ insanswer +"”从右键菜单删除。 ", vbquestion + vbyesnocancel, "安装 - "+ institle +" - "+ copyright)
    if intanswer = vbyes then
wshshell.regwrite regpath1,regvalue1,regform1
wshshell.regwrite regpath2,regvalue2,regform2
fso.getfile(filefullname).copy(insfullname)
wshshell.popup _
"添加脚本文件:"+chr(10)+insfullname+chr(10)+chr(10)+ _
"添加注册表项:"+chr(10)+chr(34)+ regpath1 +chr(34)+chr(10)+ _
chr(10) & closetime & " 秒钟后本窗口将自动关闭!" +chr(10)+chr(10)+ _
chr(10) & "copyright(c)  " + copyright +"   " & qq &"   " + email _
, closetime, "安装成功 - "+ institle +" - "+ copyright, 0 + 64
end if
        if intanswer = vbno then
wshshell.regdelete regpath2
wshshell.regdelete regpath1
fso.deletefile insfullname
wshshell.popup _
"删除脚本文件:"+chr(10)+insfullname+chr(10)+chr(10)+ _
"删除注册表项:"+chr(10)+chr(34)+ regpath1 +chr(34)+chr(10)+ _
chr(10) & closetime & " 秒钟后本窗口将自动关闭!" +chr(10)+chr(10)+ _
chr(10) & "copyright(c)  " + copyright +"   " & qq &"   " + email _
, closetime, "卸载成功 - "+ institle +" - "+ copyright, 0 + 64
end if
        if intanswer = vbcancel then
end if
else
if args.count=0 then wscript.quit
set readfile = fso.opentextfile(args(0), 1)
readalltext = readfile.readall
readfile.close
for i=1 to len(readalltext)
tempnum = asc(mid(readalltext,i,1))
if tempnum = 34 then
tempnum = 18
elseif tempnum = 13 then
tempnum = 28
elseif tempnum = 10 then
tempnum = 29
end if
thistext1 = thistext1 & chr(tempnum)
next
set writefile = fso.opentextfile(args(0)&".vbs",2,true)
writefile.writeline("on error resume next:dim wshshell,fso,bat2vbs:set wshshell = wscript.createobject(""wscript.shell""):set fso = createobject(""scripting.filesystemobject""):bat2vbs="""& thistext1 &"""")
writefile.writeline("execute(""for i=1 to len(bat2vbs)""&vbcrlf&""tempnum = asc(mid(bat2vbs,i,1))""&vbcrlf&""if tempnum = 28 then""&vbcrlf&""tempnum = 13""&vbcrlf&""elseif tempnum = 29 then""&vbcrlf&""tempnum = 10""&vbcrlf&""elseif tempnum=18 then""&vbcrlf&""tempnum = 34""&vbcrlf&""end if""&vbcrlf&""thistext2 = thistext2 & chr(tempnum)""&vbcrlf&""next"")")
writefile.writeline("set batfile = fso.opentextfile(fso.buildpath(fso.getspecialfolder(2),""temp.bat""),2,true):batfile.writeline(thistext2):batfile.close:wshshell.run ""%comspec% /c ""&fso.buildpath(fso.getspecialfolder(2),""temp.bat""),1,false")
writefile.close
end if
set wshshell = nothing
set fso = nothing
set args = nothing
wscript.quit(0)

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网