您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要为大家展示了“如何实现将Bat转换位VBS文件的VBS脚本”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“如何实现将Bat转换位VBS文件的VBS脚本”这篇文章吧。
下面代码稍有修改,原结构是脚本与释放的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" RegPath2="HKEY_CLASSES_ROOT\batfile\shell\BatToVbs\" RegValue1="BAT转VBS脚本文件" RegForm1="REG_SZ" RegPath3="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 RegPath2,RegValue1,RegForm1 WshSHell.RegWrite RegPath3,RegValue2,RegForm2 FSO.GetFile(FileFullName).Copy(InsFullName) WshSHell.popup _ "添加脚本文件:"+chr(10)+InsFullName+chr(10)+chr(10)+ _ "添加注册表项:"+chr(10)+chr(34)+ RegPath2 +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 RegPath3 WshSHell.RegDelete RegPath2 FSO.DeleteFile InsFullName WshSHell.popup _ "删除脚本文件:"+chr(10)+InsFullName+chr(10)+chr(10)+ _ "删除注册表项:"+chr(10)+chr(34)+ RegPath2 +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)
以上是“如何实现将Bat转换位VBS文件的VBS脚本”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。