タグ
  ANSI (1)
  ASP.NET (10)
  Active Directory (55)
  BAT (16)
  Backup (2)
  CSharp (11)
  CentOS (4)
  C言語 (4)
  DNS (4)
  Excel (3)
  FFmpeg (1)
  Fedora (4)
  FreeBSD (6)
  IPv6 (3)
  Java (11)
  JavaScript (8)
  LAN (1)
  Link (4)
  Linux (15)
  Mac (1)
  Mail (2)
  Microsoft (3)
  NIS (1)
  Node.js (6)
  OpenIndiana (1)
  OpenLDAP (2)
  OpenSSL (1)
  OpenSolaris (4)
  PHP (2)
  Perl (2)
  Postfix (1)
  PostgreSQL (2)
  PowerShell (34)
  RFC (3)
  SQL Server (5)
  Solaris (10)
  Ubuntu (9)
  VBScript (73)
  VCpp (2)
  VMware (3)
  Visual Basic (1)
  WMI (17)
  WSF (5)
  WSH (10)
  Windows (19)
  bash (1)
  bind (1)
  iSCSI (1)
  おまけ (3)
  作成中 (8)
  慣用句 (3)
  正規表現 (6)
  運用 (8)
作成 2010.01.05
更新 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()
[リロード] [記事修正] [新規作成] [使用方法]
©2004-2012 UPKEN IPv4