'-Begin-----------------------------------------------------------------
'-
'- Example how to use a DLL call via PowerShell with component
'- ActiveXPosh inside SAP GUI Scripting
'-
'-----------------------------------------------------------------------
'-Directives----------------------------------------------------------
Option Explicit
'-Constants-----------------------------------------------------------
Const OUTPUT_CONSOLE = 0
Const OUTPUT_WINDOW = 1
Const OUTPUT_BUFFER = 2
'-Variables-----------------------------------------------------------
Dim PSCode
'-Sub Add-------------------------------------------------------------
Sub Add(Code)
PSCode = PSCode & Code & vbCrLf
End Sub
'-Sub Main------------------------------------------------------------
Sub Main()
'-Variables-------------------------------------------------------
Dim SapGuiAuto, application, connection, session
Dim PS
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If Not IsObject(PS) Then
Set PS = CreateObject("SAPIEN.ActiveXPoSH")
If PS.Init(vbFalse) <> 0 Then
MsgBox "Can't instantiate PowerShell engine"
Exit Sub
End If
If PS.IsPowerShellInstalled = vbFalse Then
Msgbox "PowerShell is not installed"
Exit Sub
End If
End If
PS.OutputMode = OUTPUT_BUFFER
'-PowerShell Begin------------------------------------------------------
PSCode = ""
Add "$sig = @"""
Add "[DllImport(""User32.dll"")]"
Add "public static extern int MessageBoxA(int hWnd, String Text, String Caption, int Type);"
Add """@;"
Add "$DLL_User32 = Add-Type PBexpMsgBox -MemberDefinition $sig -PassThru"
Add "$DLL_User32::MessageBoxA(0, ""Hello World"", ""From WinAPI"", 0);"
PS.Execute(PSCode)
'-PowerShell End--------------------------------------------------------
session.findById("wnd[0]/tbar[0]/okcd").text = "/nSE38"
session.findById("wnd[0]/tbar[0]/btn[0]").press
End Sub
'-Main----------------------------------------------------------------
Main()
'-End-------------------------------------------------------------------
'-Begin-----------------------------------------------------------------
'-
'- Example how to use a dotNET VB# code via PowerShell with component
'- ActiveXPosh inside SAP GUI Scripting
'-
'-----------------------------------------------------------------------
'-Directives----------------------------------------------------------
Option Explicit
'-Constants-----------------------------------------------------------
Const OUTPUT_CONSOLE = 0
Const OUTPUT_WINDOW = 1
Const OUTPUT_BUFFER = 2
'-Variables-----------------------------------------------------------
Dim PSCode
'-Sub Add-------------------------------------------------------------
Sub Add(Code)
PSCode = PSCode & Code & vbCrLf
End Sub
'-Sub Main------------------------------------------------------------
Sub Main()
'-Variables-------------------------------------------------------
Dim SapGuiAuto, application, connection, session
Dim PS, str, outText
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If Not IsObject(PS) Then
Set PS = CreateObject("SAPIEN.ActiveXPoSH")
If PS.Init(vbFalse) <> 0 Then
MsgBox "Can't instantiate PowerShell engine"
Exit Sub
End If
If PS.IsPowerShellInstalled = vbFalse Then
Msgbox "PowerShell is not installed"
Exit Sub
End If
End If
PS.OutputMode = OUTPUT_BUFFER
'-PowerShell Begin------------------------------------------------------
PSCode = ""
Add "$VBCode = @"""
'-VB# Begin-------------------------------------------------------------
Add "Option Strict On"
Add "Imports System"
Add "Imports Microsoft.VisualBasic"
Add "Namespace VBCode"
Add " Public Class VB"
Add " Public Shared Function Hello1() As String"
Add " Return ""Hello World!"""
Add " End Function"
Add " Public Function Hello2(ByVal Name As String) As String"
Add " Return ""Hello "" & Name & ""!"""
Add " End Function"
Add " Public Sub Hello3(ByVal Name As String)"
Add " MsgBox(Name, MsgBoxStyle.OkOnly, ""Hello"")"
Add " End Sub"
Add " End Class"
Add "End Namespace"
'-VB# End---------------------------------------------------------------
Add """@;"
Add "Add-Type -TypeDefinition $VBCode -Language VisualBasic"
Add "$VB = new-Object VBCode.VB"
Add "[VBCode.VB]::Hello1()"
Add "$VB.Hello2(""Stefan"")"
Add "$VB.Hello3(""Stefan"")"
PS.Execute(PSCode)
'-PowerShell End--------------------------------------------------------
For Each str In PS.Output
outText = outText & str & vbCrLf
Next
MsgBox outText
session.findById("wnd[0]/tbar[0]/okcd").text = "/nSE16"
session.findById("wnd[0]/tbar[0]/btn[0]").press
End Sub
'-Main----------------------------------------------------------------
Main()
'-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 |
---|---|
37 | |
10 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 | |
2 | |
2 |