Skip to Content
Author's profile photo Pedro Magueija

How to find the SAP Business One process ID

Hi guys,

I’ve always struggled with finding the correct process id of the SAP Business One a given add-on connects with.

This becomes a necessity when displaying window dialogs, or when we need to grab window handles from SAP Business One client (for whatever reason).

Many solutions involve using the OS API which has been unreliable in my experience and would fail when running our addon from a development environment such as Visual Studio.

For that reason, I’ve set out to find a way to find the process id our add-on connects to.

I’ve found a way which I can share with you because it has been, so far, pretty accurate.

Here is the code:

var gui = new SboGuiApi();
gui.Connect(ConnectionString);
var application = gui.GetApplication();

var appId = application.AppId;
var processes = System.Diagnostics.Process.GetProcessesByName(@"SAP Business One");

foreach (var process in processes)
{
    try
    {
        var processAppId = gui.GetAppIdFromProcessId(process.Id);
        if(appId == processAppId)
        {
            return process.Id;
        }
    }
    catch (COMException)
    {
        // GetAppIdFromProcessId will throw when the current process is not the one we are connected to
        continue;
    }
}

The code connects to SAP Business One and extracts the appId which is the specific id of the client you connect to.

Then it asks for all processes named SAP Business One and iterates over them. It then uses the GetAppIdFromProcessId to extract the appId of that process. If the extracted appId matches our current appId then this is the process we connect to, and it returns the process id.

This way we will reliably get the process id our add-on connects to. I’ve managed to test this in single machine environments and terminal services environments.

If anyone can leave comments on Citrix environments that would be great.

I hope you’ll find this useful.

Cheers.

 

Pedro Magueija

LinkedIn | Twitter | Blog

Assigned tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Edy Simon
      Edy Simon

      Hi Pedro,

      This is good as long as you are serving desktop client.
      However, windows dialog cannot be used in SBO web access.

      Cheers

       

      Author's profile photo Pedro Magueija
      Pedro Magueija
      Blog Post Author

      Hi Edy,

       

      You’re right about the Windows Dialogs, but this method will grab the process id of the Business One client regardless of whether you are in a Browser Access client or a regular client.

      Pedro Magueija

      LinkedIn | Twitter | Blog

      Author's profile photo Edy Simon
      Edy Simon

      Hi Pedro,

      Yes, Indeed.
      I totally missed your point, in my mind I only thought of Folder/File browser when i needed the pid.

      Cheers
      Edy