"-Begin-----------------------------------------------------------------
Program zUseVBSharp.
"-TypePools---------------------------------------------------------
Type-Pools OLE2 .
"-Constants--------------------------------------------------------
Constants OUTPUT_CONSOLE Type i Value 0.
Constants OUTPUT_WINDOW Type i Value 1.
Constants OUTPUT_BUFFER Type i Value 2.
"-Variables---------------------------------------------------------
Data PS Type OLE2_OBJECT.
Data Result Type i Value 0.
Data strResult Type String Value ''.
Data tabResult Type Table Of String.
Data PSCode Type String Value ''.
"-Macros------------------------------------------------------------
Define _.
Concatenate PSCode &1 cl_abap_char_utilities=>cr_lf Into PSCode.
End-Of-Definition.
"-Main--------------------------------------------------------------
Create Object PS ' SAPIEN.ActiveXPoSHV3'.
If sy-subrc = 0 And PS-Handle <> 0 And PS-Type = 'OLE2'.
Call Method Of PS 'Init' = Result Exporting #1 = 0.
If Result = 0.
Call Method Of PS 'IsPowerShellInstalled' = Result.
If Result <> 0.
Set Property Of PS 'OutputMode' = OUTPUT_BUFFER.
"-PowerShell Begin------------------------------------------------------
_ '$VBCode = @"'.
"-VB# Begin-------------------------------------------------------------
_ 'Option Strict On'.
_ 'Imports System'.
_ 'Imports Microsoft.VisualBasic'.
_ 'Namespace VBCode'.
_ ' Public Class VB'.
_ ' Public Shared Function Hello1() As String'.
_ ' Return "Hello World!"'.
_ ' End Function'.
_ ' Public Function Hello2(ByVal Name As String) As String'.
_ ' Return "Hello " & Name & "!"'.
_ ' End Function'.
_ ' Public Sub Hello3(ByVal Name As String)'.
_ ' MsgBox(Name, MsgBoxStyle.OkOnly, "Hello")'.
_ ' End Sub'.
_ ' End Class'.
_ 'End Namespace'.
"-VB# End---------------------------------------------------------------
_ '"@;'.
_ 'Add-Type -TypeDefinition $VBCode -Language VisualBasic'.
_ '$VB = new-Object VBCode.VB'.
_ '[VBCode.VB]::Hello1()'.
_ '$VB.Hello2("Stefan")'.
_ '$VB.Hello3("Stefan")'.
"-PowerShell End--------------------------------------------------------
Call Method Of PS 'Execute' Exporting
#1 = PSCode.
Call Method Of PS 'OutputString' = strResult.
Split strResult At cl_abap_char_utilities=>cr_lf
Into Table tabResult.
Loop At tabResult Into strResult.
Write: / strResult.
EndLoop.
EndIf.
EndIf.
Free Object PS.
EndIf.
"-End-------------------------------------------------------------------
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
5 | |
4 | |
3 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |