I am working on a script that will start SAP if it's not already running and run a report.
I thought I was successful, but at some point, the logon portion of the script stopped functioning.
The Logon screen opens fine, but the status code never changes from 0 to 1 and the script hangs. The status only changes if I close the Logon window, but an error is thrown because the SAPGUI no longer exists at that point.
If I simply put in a delay of a few seconds the script continues just fine, but I want a more reliable way of ensuring that SAP is already running. I'm not sure what the problem is or why it sometimes works.
Set WshShell = CreateObject("WScript.Shell") Set proc = WshShell.Exec("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe") Do While proc.Status = 0 WScript.Sleep 1000 Loop Set SapGui = GetObject("SAPGUI") Set application = SapGui.GetScriptingEngine Set Connection = application.Openconnection("Work management [PR1]", True) Set session = Connection.Children(0)