更多信息
如果要查找编译器,您需要针对每个已安装的 .net 版本执行以下命令:
在命令提示符中键入。
dir c:\Windows\Microsoft.NET\vbc.exe /a/s
Windows Forms
Windows Forms版本(无控制台窗口,我们实际上不创建任何表单 - 虽然您可以这样做)。
在命令提示符中编译以下行。
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /t:winexe "%userprofile%\desktop\VBS2Exe.vb"
VBS2EXE.vb的文本
Imports System.Windows.Forms
Partial Class MyForm : Inherits Form
Private Sub InitializeComponent()
End Sub
Public Sub New()
InitializeComponent()
End Sub
Public Shared Sub Main()
Dim sc as object
Dim Scrpt as string
sc = createObject("MSScriptControl.ScriptControl")
Scrpt = "msgbox " & chr(34) & "Hi there I'm a form" & chr(34)
With SC
.Language = "VBScript"
.UseSafeSubset = False
.AllowUI = True
End With
sc.addcode(Scrpt)
End Sub
End Class
使用这些可选参数可以为您提供一个图标和清单。清单允许您指定以常规方式运行,如果是管理员则以提升的方式运行,仅以提升的方式运行等。
/win32icon:指定默认的Win32资源的Win32图标文件(.ico)。
/win32manifest:所提供的文件嵌入输出PE的清单部分中。
理论上,我已经关闭了UAC,因此无法进行测试,但是将此文本文件放在桌面上并将其命名为vbs2exe.manifest,保存为UTF-8。
命令行
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /t:winexe /win32manifest:"%userprofile%\desktop\VBS2Exe.manifest" "%userprofile%\desktop\VBS2Exe.vb"
清单文件
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0"> <assemblyIdentity version="1.0.0.0"
processorArchitecture="*" name="VBS2EXE" type="win32" />
<description>Script to Exe</description>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
<security> <requestedPrivileges>
<requestedExecutionLevel level="requireAdministrator"
uiAccess="false" /> </requestedPrivileges>
</security> </trustInfo> </assembly>
希望它现在只能作为管理员运行。
给予主机对象的访问权限
以下是一个示例,将vbscript授予访问.NET对象的权限。
Imports System.Windows.Forms
Partial Class MyForm : Inherits Form
Private Sub InitializeComponent()
End Sub
Public Sub New()
InitializeComponent()
End Sub
Public Shared Sub Main()
Dim sc as object
Dim Scrpt as string
sc = createObject("MSScriptControl.ScriptControl")
Scrpt = "msgbox " & chr(34) & "Hi there I'm a form" & chr(34) & ":msgbox meScript.state"
With SC
.Language = "VBScript"
.UseSafeSubset = False
.AllowUI = True
.addobject("meScript", SC, true)
End With
sc.addcode(Scrpt)
End Sub
End Class
嵌入版本信息
下载vbs2exe.res文件,网址为https://skydrive.live.com/redir?resid=E2F0CE17A268A4FA!121 ,将其放置在桌面上。
下载ResHacker,网址为http://www.angusj.com/resourcehacker
在ResHacker中打开vbs2exe.res文件,进行编辑并点击编译按钮。然后在“文件”菜单中选择“保存”选项。
输入:
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /t:winexe /win32manifest:"%userprofile%\desktop\VBS2Exe.manifest" /win32resource:"%userprofile%\desktop\VBS2Exe.res" "%userprofile%\desktop\VBS2Exe.vb"