作成 2010.01.05
更新 2011.11.27
更新 2011.11.27
PowerShell で他言語を使用する Visual Basic 編
このサンプルは、クリップボードにコピーします。
$provider = New-Object Microsoft.VisualBasic.VBCodeProvider $params = New-Object System.CodeDom.Compiler.CompilerParameters $params.GenerateInMemory = $True $refs = "System.dll","Microsoft.VisualBasic.dll","System.Data.DLL", ` "System.management.dll","System.DirectoryServices.dll" $params.ReferencedAssemblies.AddRange($refs) # VB.NET EXAMPLE $txtCode = ' Imports Microsoft.VisualBasic Imports System Imports System.Threading Public Class clip Public Shared clip_data As String Sub Main() Dim newThread As Thread = New Thread(AddressOf ThreadMethod) newThread.SetApartmentState(ApartmentState.STA) newThread.Start() End Sub Public Property clip_text() As String Get Return clip_data End Get Set(ByVal value As String) clip_data = value End Set End Property Shared Sub ThreadMethod() Dim Comp As New Microsoft.VisualBasic.Devices.computer Comp.clipboard.setText(clip_data) End Sub End Class ' # コンパイルエラーは $results.Errors で取得できる $results = $provider.CompileAssemblyFromSource($params, $txtCode) $mAssembly = $results.CompiledAssembly $i = $mAssembly.CreateInstance("clip") $i.clip_text = "hello clip" $r = $i.Main()