より詳しい情報
コンパイラを見つけるには、.netバージョンごとに1つインストールし、コマンドプロンプトを入力します。
dir c:\Windows\Microsoft.NET\vbc.exe /a/s
Windowsフォーム
Windowsフォームバージョンの場合(コンソールウィンドウがなく、実際にフォームを作成することはできませんが、必要に応じて作成できます)。
コマンドプロンプトで行をコンパイルします。
"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
バージョン情報を埋め込むには
https://skydrive.live.com/redir?resid=E2F0CE17A268A4FA!121からvbs2exe.resファイルをダウンロード し、デスクトップに配置します。
http://www.angusj.com/resourcehackerからResHackerをダウンロードします
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"