Académique Documents
Professionnel Documents
Culture Documents
'-
'- VBScript to start SAP Logon if process doesn't exists and connect
'- to an SAP system. The SAP Logon process is detected via WMI
'- (Windows Management Instrumentarium), also the termination.
'-
'-----------------------------------------------------------------------
'-Directives----------------------------------------------------------
Option Explicit
'-Variables-----------------------------------------------------------
Dim SAPLogon, SAPLogonTitle
SAPLogon = "saplogon.exe" : SAPLogonTitle = "SAP Logon 740"
'SAPLogon = "saplgpad.exe" : SAPLogonTitle = "SAP Logon Pad 740"
Dim SysDescr, SysIP
SysDescr = "NSP" : SysIP = "192.168.203.134"
'-Function FindProcess------------------------------------------------
Function FindProcess(ProcessName)
'-Variables-------------------------------------------------------
Dim WMIServ, Processes, Process
FindProcess = False
End Function
'-Sub TerminateProcess------------------------------------------------
Sub TerminateProcess(ProcessName)
'-Variables-------------------------------------------------------
Dim WMIServ, Processes, Process
End Sub
'-Function GetSAPGUIObject--------------------------------------------
'-
'- This function starts the SAP Logon if it is necessary and delivers
'- its object
'-
'---------------------------------------------------------------------
Function GetSAPGUIObject()
'-Variables-------------------------------------------------------
Dim WshShell, Exec
If FindProcess(SAPLogon) Then
Set GetSAPGUIObject = GetObject("SAPGUI")
Else
Set WshShell = CreateObject("WScript.Shell")
Set Exec = WshShell.Exec(_
"c:\Program Files (x86)\SAP\FrontEnd\SAPgui\" & SAPLogon)
Do While Not WshShell.AppActivate(SAPLogonTitle)
WScript.Sleep 500
Loop
Set GetSAPGUIObject = GetObject("SAPGUI")
End If
End Function
'-Sub Main------------------------------------------------------------
Sub Main()
'-Variables-------------------------------------------------------
Dim SapGuiAuto, Application, Connection, Session
'-----------------------------------------------------------------
'-
'- Here you have the possibility to decide which way you want to
'- use, on the one hand via system description or on the other
'- hand via IP address
'-
'-----------------------------------------------------------------
'Set Connection = Application.OpenConnection(SysDescr, True)
Set Connection = Application.OpenConnectionByConnectionString(_
"/H/" & SysIP, True)
If Not IsObject(Connection) Then
Set Application = Nothing
Set SapGuiAuto = Nothing
Exit Sub
End If
MyScript(Session)
End Sub
'-Sub MyScript--------------------------------------------------------
Sub MyScript(Session)
End Sub
'-Main----------------------------------------------------------------
Main
'-End-------------------------------------------------------------------