1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Alibre API is not running when called from win system service application

Discussion in 'Add-on Development' started by m.marek, Oct 16, 2019.

  1. m.marek

    m.marek Member


    I wrote a Windows service application and installed it, but the function GetActiveObjets return FAILED result (even if Alibre is working). The same code works good in a standard VCL application.

    hr = GetActiveObject (clsid, NULL, &pUnk);
    if (FAILED (hr))
    SaveLogFile("Alibre is OFF");

    Any ideas how to use it from windows service application.

  2. simonb65

    simonb65 Alibre Super User

    If it fails to find an active instance of Alibre, i.e.GetActiveObject returns null, So, just start an instance ...

    i,.e. in C#

    System.Diagnostics.Process process;
    IADRoot root;
    // get the alibre object
    IAutomationHook hook = (IAutomationHook)Marshal.GetActiveObject("AlibreX.AutomationHook");
    if (hook == null)
        // start alibre
        process = System.Diagnostics.Process.Start(@"C:\Program Files\Alibre Design\Program\Alibre Design.exe");
        // now get the alibre object
        hook = (IAutomationHook)Marshal.GetActiveObject("AlibreX.AutomationHook");
    if (hook != null)
        // success
        root = (IADRoot)hook.Root;
        Console.Debug("Connected to Alibre Design Version: " + root.Version);
        // failed!
        Console.Debug("Failed to connect to Alibre!");
    There is further error handling to consider (i.e. if the process fails, alibre exe doesn't exist, second attempt at getting the hook fails because it takes time to start the Alibre process, etc)

    From a service, you may also need to consider permissions and what that service can/can't do!

    If you don't want to see the UI, you can start it without ... I'll let you figure that one out! ;)
    Last edited: Oct 16, 2019
  3. m.marek

    m.marek Member

    I can't just start a new istance bacause the main idea of this appliacation was to check if the Alibre is running or not - its a part of design time control
  4. simonb65

    simonb65 Alibre Super User

    What error code does GetActiveObject return??
  5. m.marek

    m.marek Member

    Return value is: -2147221021
    Looks like: Code 483 / COM/OLE Interface

    Any ideas?
  6. simonb65

    simonb65 Alibre Super User

    -2147221021 is code is 0x800401E3 which is 'Operation unavailable'.

    For security reasons (since Vista) you can't get information about or interact with desktop applications from a service and Alibre by definition (because it has a UI thread) is a desktop application. If you want do a background operation from startup, write an application and assign it to the 'startup' tasks. Then it will be running at the same access levels as Alibre, or set your application to run as a scheduled task.
  7. m.marek

    m.marek Member

    There is the same situation when trying to run my software from Task Sheduler.
    Return code is 0x800401E3
  8. simonb65

    simonb65 Alibre Super User

  9. BobSchaefer

    BobSchaefer Member

    I would question why you're doing a check for the application to be running using this method to begin with? There are much easier methods of determining if an application is running or not, primarily by searching for the process itself, rather than attempting to access the API and having to deal with everything associated with that. My other question would be, what are you really attempting to do with this? It doesn't make sense to have a system service that is just attempting to keep alibre constantly running...
    NateLiqGrav likes this.

Share This Page