cancel
Showing results for 
Search instead for 
Did you mean: 

SAP Logon Script - Process Status Never Changes

Former Member
0 Kudos

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)

Accepted Solutions (1)

Accepted Solutions (1)

script_man
Active Contributor
0 Kudos

Hi Julio,

you can try the following:

Set WshShell = CreateObject("WScript.Shell")

Set proc = WshShell.Exec("C:\Program Files (x86)\SAP\FrontEnd\SAPgui\saplogon.exe")

'Do While proc.Status = 0

myError = 1

on error resume next

Do While myError <> 0   

     WScript.Sleep 1000

'Loop 

     Set SapGui = GetObject("SAPGUI")

     Set application = SapGui.GetScriptingEngine

     myError = err.number

Loop

on error goto 0

Set Connection = application.Openconnection("Work management [PR1]", True)

Set session = Connection.Children(0)

Regards,

ScriptMan

Former Member
0 Kudos

I see what's happening, the script will throw an error until the object is defined (i.e. when saplogon.exe is running). Thanks for the idea. I would really like to know why the saplogon process will not change Status until I close the logon window.

I was playing around with this and came up with a much more complicated solution.

I implemented a function that checks if the saplogon.exe process is running. If it's in the object table, the script should be able to grab the SAPGUI object.


Function sapRunning

Const strComputer = "."

Dim objWMIService, colProcessList

    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

    Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process Where Name = 'saplogon.exe'")

    If (colProcessList.Count > 0) Then

        sapRunning = true

    Else

        sapRunning = false

    End If      

End Function  

Answers (0)