What's new

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

m.marek

Member
Hello,

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");
return;
}


Any ideas how to use it from windows service application.

BR
Marcin
 

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#

Code:
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);
}
else
{
    // 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:

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
 

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.
 

BobSchaefer

Senior 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...
 
Top