如何将VBScript转换为可执行(EXE)文件? [英] How can I convert a VBScript to an executable (EXE) file?

查看:176
本文介绍了如何将VBScript转换为可执行(EXE)文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找将VBScript (*.vbs)转换为可执行文件的信息,并意识到大多数可用工具实际上是将脚本包装在可执行文件中.尝试了一些工具,但效果不如预期.我尝试使用IExpress(在Windows XP中)创建Win32自解压cab文件,但在Windows 7计算机上无法正确调用.

I'd looked around for information to convert a VBScript (*.vbs) to an executable and realised that most of the tools available are actually wrapping the script in the executable. Tried a few tools and it didn't worked as well as expected. I tried IExpress (in Windows XP) to create the Win32 self extraction cab file but it didn't invoke properly on Windows 7 machines.

所以我正在寻找一种将vbs编译成exe的方法.我正在尝试将当前脚本移植到VB Express 2008中,但是我对Visual Basic并不了解.有很多错误,但我仍在尝试.

So I am looking for a way to compile the vbs into exe. I am trying to port my current script into VB Express 2008 but I have no prior knowledge of Visual Basic here. There are a lot of errors but I am still trying around.

任何人都可以请我从这里继续进行建议吗?我的意思是,自解压存档代替独立的可执行文件是一种方法吗?但是说像Winzip一样,我不知道如何使它在提取后运行脚本.

Can anyone please advice on how should I proceed from here? I mean, would a self extracting archive be the way to go instead of a standalone executable file? But say like Winzip I don't know how to make it run the script after extraction.

有什么想法吗?

推荐答案

由于VBScript不是编译的,因此无法将VBScript(.vbs文件)转换为可执行文件(.exe文件).语言.将源代码转换为本地可执行代码的过程称为编译" ,而脚本语言(例如VBScript)不支持.

There is no way to convert a VBScript (.vbs file) into an executable (.exe file) because VBScript is not a compiled language. The process of converting source code into native executable code is called "compilation", and it's not supported by scripting languages like VBScript.

当然,您可以使用WinZip之类的脚本将脚本添加到自解压存档中,但是要做的就是对其进行压缩.令人怀疑的是文件大小是否会明显缩小,并且由于它是一开始的纯文本文件,因此实际上根本没有必要对其进行压缩. 自解压存档的唯一目的是最终用户的计算机上不需要解压缩软件(例如WinZip)即可解压或解压缩"文件.如果一开始就没有压缩,那么这是有争议的.

Certainly you can add your script to a self-extracting archive using something like WinZip, but all that will do is compress it. It's doubtful that the file size will shrink noticeably, and since it's a plain-text file to begin with, it's really not necessary to compress it at all. The only purpose of a self-extracting archive is that decompression software (like WinZip) is not required on the end user's computer to be able to extract or "decompress" the file. If it isn't compressed in the first place, this is a moot point.

或者,正如您所提到的,有几种方法可以将VBScript代码文件包装到一个独立的可执行文件中,但是这些只是包装程序,当用户双击时,它们可以自动执行脚本(处于当前的未编译状态). exe文件.我想这可以带来好处,但是听起来不像您要找的东西.

Alternatively, as you mentioned, there are ways to wrap VBScript code files in a standalone executable file, but these are just wrappers that automatically execute the script (in its current, uncompiled state) when the user double-clicks on the .exe file. I suppose that can have its benefits, but it doesn't sound like what you're looking for.

为了将您的VBScript真正转换为可执行文件,您将不得不使用另一种可以编译的语言来重写它. Visual Basic 6 (在引入.NET Framework之前,是VB的最新版本)在语法上与VBScript非常相似,但确实支持编译为本机代码.如果将VBScript代码移动到VB 6,则可以将其编译为本机可执行文件.运行.exe文件将要求用户具有

In order to truly convert your VBScript into an executable file, you're going to have to rewrite it in another language that can be compiled. Visual Basic 6 (the latest version of VB, before the .NET Framework was introduced) is extremely similar in syntax to VBScript, but does support compiling to native code. If you move your VBScript code to VB 6, you can compile it into a native executable. Running the .exe file will require that the user has the VB 6 Run-time libraries installed, but they come built into most versions of Windows that are found now in the wild.

或者,您可以继续跳至 Visual Basic .NET ,它的语法与VB 6和VBScript保持有点相似(尽管它几乎不像剪切和粘贴迁移一样). VB.NET程序也将编译为.exe文件,但它们要求将.NET Framework运行时安装在用户的计算机上.幸运的是,这也变得司空见惯,如果您的用户恰巧没有它,可以很容易地重新分配它.您在问题中提到了这条路线(将当前脚本移植到使用VB.NET的VB Express 2008中),但是您遇到了很多错误.我的意思是,它与剪切粘贴迁移相去甚远. VB 6/VBScript与VB.NET之间存在一些巨大差异,尽管这些语法在表面上有相似之处.如果您需要迁移VBScript的帮助,可以在此处在Stack Overflow上发布问题.最终,这可能是您想要做的最好的方法,但是我不能保证这会很简单.

Alternatively, you could go ahead and make the jump to Visual Basic .NET, which remains somewhat similar in syntax to VB 6 and VBScript (although it won't be anywhere near a cut-and-paste migration). VB.NET programs will also compile to an .exe file, but they require the .NET Framework runtime to be installed on the user's computer. Fortunately, this has also become commonplace, and it can be easily redistributed if your users don't happen to have it. You mentioned going this route in your question (porting your current script in to VB Express 2008, which uses VB.NET), but that you were getting a lot of errors. That's what I mean about it being far from a cut-and-paste migration. There are some huge differences between VB 6/VBScript and VB.NET, despite some superficial syntactical similarities. If you want help migrating over your VBScript, you could post a question here on Stack Overflow. Ultimately, this is probably the best way to do what you want, but I can't promise you that it will be simple.

这篇关于如何将VBScript转换为可执行(EXE)文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆