cancel
Showing results for 
Search instead for 
Did you mean: 

Automate SAP start and log in using VBScript

12-30-2021 11:39 AM
2311 views 1 comments
0 Likes
SAP Managed Tags
Subscribe

Hello! I am creating a scritp to start SAP application via Windows Prompt, log into it and then start using a transaction. The steps are:

  1. Start SAP executable (saplgpad.exe).
  2. Open SAP ECC - PRD window (SID: EP0).
  3. Log in to my account.

However, I am having trouble when doing step 2. Could someone help me please?

Below is my code. I am using the following command do run the .vbs file: C:\Users\*******\AppData\Roaming\SAP\SAP GUI\Scripts>cscript ScriptName.vbs

Dim WSHShell, SAPGUIPath, Name, SID, InstanceNo, objapp, WinTitle

Set WSHShell = WScript.CreateObject("WScript.Shell")

If IsObject(WSHShell) Then
    SAPGUIPath = "C:\Program Files (x86)\SAP\FrontEnd\SAPgui\"
    Name = """SAP ECC - PRD"""
    SID = "EP0"
    InstanceNo = "00"
    Set objapp = WSHShell.Exec SAPGUIPath & "saplgpad.exe " & Name & " " & InstanceNo
    WinTitle = "SAP"
    While Not WSHShell.AppActivate(WinTitle)
      WScript.Sleep 250
    Wend
    Set WSHShell = Nothing
End If

session.findById("wnd[0]").maximize
On Error Resume Next
session.findById("wnd[0]/usr/txtRSYST-MANDT").Text = "100"
On Error Resume Next
session.findById("wnd[0]/usr/txtRSYST-BNAME").text = "*******"
On Error Resume Next
session.findById("wnd[0]/usr/pwdRSYST-BCODE").text = "*********"
On Error Resume Next
session.findById("wnd[0]/usr/txtRSYST-LANGU").Text = "PT"
On Error Resume Next
session.findById("wnd[0]").sendVKey 0<br>
0 Likes

Accepted Solutions (0)

Answers (0)