cancel
Showing results for 
Search instead for 
Did you mean: 

Exit SAP Application

Former Member
0 Kudos

Hai To All,

While starting my addon iam checking some condition if it returns false i need to terminate the SAP application.

How to do that????

Regards,

Anitha

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Do u need to terminate ur Addon or whole SAP application..??

TO stop ur add-on application use

System.Windows.Forms.Application.Exit()

To exit whole SAP application, i guess u can Declare a process and Exit it or stop it, just look in google for some samples to stop the application in by exiting a process.

Hope it helps,

Vasu Natari.

Former Member
0 Kudos

Thanks for ur immediate reply vasu,

Not Addon,I need to close the whole SAP Application.....

Regards,

Anitha

Nussi
Active Contributor
0 Kudos

Hi Ani,

two solutions to close the business one client:

1. use SBOApplication.SendKeys and send Ctrl+Q

or

2. SBOApplication.ActivateMenuItem("526")

point 2 is my favourit

lg David

Former Member
0 Kudos

Agreed with David....

The easiest activate the menu cilck ok Exit ("526").

Vasu Natari.

Former Member
0 Kudos

Its Ok David,

But i didt connect my addon or company.....Before that itself i need to close the application..

Here is my snippet Code,

If CheckIfServiceIsRunning("Found") = True Then

SetApplication()

.....

....

Else

System.Windows.Forms.MessageBox.Show("Run The Setup File!!!!")

System.Windows.Forms.Application.ExitThread()

System.Windows.Forms.Application.Exit()

endif

Here how to give the menuitem????

Regards,

Anitha

Former Member
0 Kudos

Then if thats the case u need to exit the EXE.

Just check the below function which i found on google, i guess u could modify it to exit the SAP Application. In the sample he is starting the exe.

Public Function StartAndWait(ByVal ProcessPath As String, ByVal Licence As Integer)
        Dim startProcess As System.Diagnostics.Process
        Try
            startProcess = New System.Diagnostics.Process()
            startProcess.StartInfo.FileName = ProcessPath
            startProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            startProcess.Start()

            'Wait until the process passes back an exit code 
            startProcess.WaitForExit()

            ' Check Exit code to see if process finished without error.
            If startProcess.ExitCode <> 0 Then
                MessageBox.Show("Exit Code: " & startProcess.ExitCode)
            End If

            'Free resources associated with this process
            startProcess.Close()

            StartAndWait = True

        Catch
            StartAndWait = False
            MessageBox.Show("Could not start process " & ProcessPath, "Error")
        End Try
    End Function    Public Function StartAndWait(ByVal ProcessPath As String, ByVal Licence As Integer)
        Dim startProcess As System.Diagnostics.Process
        Try
            startProcess = New System.Diagnostics.Process()
            startProcess.StartInfo.FileName = ProcessPath
            startProcess.StartInfo.WindowStyle = ProcessWindowStyle.Normal
            startProcess.Start()

            'Wait until the process passes back an <strong class="highlight">exit</strong> code 
            startProcess.WaitForExit()

            ' Check <strong class="highlight">Exit</strong> code to see if process finished without error.
            If startProcess.ExitCode <> 0 Then
                MessageBox.Show("Exit Code: " & startProcess.ExitCode)
            End If

            'Free resources associated with this process
            startProcess.Close()

            StartAndWait = True

        Catch
            StartAndWait = False
            MessageBox.Show("Could not start process " & ProcessPath, "Error")
        End Try
    End Function

Hope it helps u,

Vasu Natari.

Former Member
0 Kudos

You should send CTRL+Q not as SBOApplication.SendKeys (becuase you arent connected) but with VB sendkeys as

SendKeys "^Q"

Former Member
0 Kudos

Thanks Petr,

But where to apply this??????///

Regards,

Anitha

Nussi
Active Contributor
0 Kudos

Anitha,

in the code you posted:


If CheckIfServiceIsRunning("Found") = True Then
  SetApplication()
  .....
  ....

Else
   System.Windows.Forms.SendKeys.Send("^(q)")
end if

if it doesn't work with q use Q

lg David

Former Member
0 Kudos

No David,

Its not working.............

Regards,

anitha

Former Member
0 Kudos

Anitha,

David`s example is true, you must use sendkeys.sendwait instead of send. The problem is, that this is sending the kez combination to active application and in debug mode the active application is in zour case VB and not SBO. If youll create addon for this, it will work.

Former Member
0 Kudos

No Petr,

Its not working.......

Regards,

Anitha

Former Member
0 Kudos

ok, I tried it and functional solution for you is:

1. Add reference to your project for System.Diagnostics (Project - Properties - References and check System.Diagnostic)

2. Use this code for closing SAP

Dim Proc() As Process = Process.GetProcesses()

For Each p As Process In Proc

If InStr(p.ProcessName, "SAP Business One") Then

p.CloseMainWindow()

End If

This works, I tested it now. Hope it helps.

Former Member
0 Kudos

Thanks Petr,

Instead of GetProcess i use GetProcessByName then its work fine.............

Thanks for ur Kind Reply,

Regards,

Anitha

Answers (0)