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

查看:27
本文介绍了如何将 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(.vbs 文件)转换为可执行文件(.exe 文件),因为 VBScript 不是经过编译的语言.将源代码转换为原生可执行代码的过程称为编译",并且它不受 脚本 语言(如 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(VB 的最新版本,在引入 .NET Framework 之前)在语法上与 VBScript 极其相似,但确实支持编译为本机代码.如果您将 VBScript 代码移至 VB 6,则可以将其编译为本机可执行文件.运行 .exe 文件将要求用户具有 VB 6 运行时库 已安装,但它们已内置于现在已广泛使用的大多数 Windows 版本中.

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天全站免登陆