可以将Bat转换位VBS文件的VBS脚本
作者 佚名
来源 ASP编程
浏览
发布时间 2013-07-09
下面代码稍有修改,原结构是脚本与释放的bat同步执行并等待bat执行完毕后删除bat,本意是不遗留临时文件。后来想想通用性不好,比如释放执行的bat文件是个常驻进程的监视类型那VBS也会无休止的等待而无法退出,所以还是改为异步执行,脚本调用bat后自行退出。考虑到还原原文件的完整性末尾添加自删除也打消了想法。压缩包暂未更新。 复制代码 代码如下: ''bat2vbs.vbsbybaomaboy DimWshSHell,FSO OnErrorResumeNext SetWshSHell=WScript.CreateObject("WScript.Shell") SetFSO=CreateObject("Scripting.FileSystemObject") SetWinVer=WshSHell.Environment("Process") SetArgs=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="Bat2Vbsbybaomaboy" InsAnswer="Bat2Vbsbybaomaboy" 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" IFFileFullName<>InsFullNamethen intAnswer=MsgBox("【是】将“"+InsAnswer+"”加入到右键菜单,"&Chr(10)&Chr(10)&"【否】将“"+InsAnswer+"”从右键菜单删除。",vbQuestion+vbYesNoCancel,"安装-"+InsTitle+"-"+Copyright) IfintAnswer=vbYesThen WshSHell.RegWriteRegPath1,RegValue1,RegForm1 WshSHell.RegWriteRegPath2,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 endif IfintAnswer=vbNoThen WshSHell.RegDeleteRegPath2 WshSHell.RegDeleteRegPath1 FSO.DeleteFileInsFullName 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 endif IfintAnswer=vbCancelThen endif ELSE ifArgs.count=0thenwscript.quit SetReadFile=FSO.OpenTextFile(Args(0),1) ReadAllText=ReadFile.ReadAll ReadFile.Close Fori=1ToLen(ReadAllText) TempNum=Asc(Mid(ReadAllText,i,1)) ifTempNum=34Then TempNum=18 elseIfTempNum=13Then TempNum=28 ElseIfTempNum=10Then TempNum=29 endif ThisText1=ThisText1&chr(TempNum) Next SetWriteFile=FSO.OpenTextFile(Args(0)&".VBS",2,True) WriteFile.WriteLine("OnErrorResumeNext:DimWshSHell,FSO,Bat2Vbs:SetWshSHell=WScript.CreateObject(""WScript.Shell""):SetFSO=CreateObject(""Scripting.FileSystemObject""):Bat2Vbs="""&ThisText1&"""") WriteFile.WriteLine("Execute(""Fori=1ToLen(Bat2Vbs)""&vbCrLf&""TempNum=Asc(Mid(Bat2Vbs,i,1))""&vbCrLf&""IfTempNum=28Then""&vbCrLf&""TempNum=13""&vbCrLf&""ElseIfTempNum=29Then""&vbCrLf&""TempNum=10""&vbCrLf&""elseifTempNum=18Then""&vbCrLf&""TempNum=34""&vbCrLf&""EndIf""&vbCrLf&""ThisText2=ThisText2&chr(TempNum)""&vbCrLf&""Next"")") WriteFile.WriteLine("SetBatFile=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 endif SetWshSHell=Nothing SetFSO=Nothing SetArgs=Nothing WScript.Quit(0) |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |
你可能对下面的文章感兴趣
关于可以将Bat转换位VBS文件的VBS脚本的所有评论