Read zenOn variables from Windows Service
Good afternoon.
I want to read variables value from zenOn Runtime project using zenOn API.
I'm working with 7.60 SP 0 Build 36068 zenOn version.
If I use a simple C# Console Application everything works correctly.
I have an exception in the below function when I use a Windows Service:
IApplication _zApplication = Marshal.GetActiveObject("zenOn.Application") as Application;
Exception:
System.Runtime.InteropServices.COMException (0x80004005). Message: Operation unavailable (Exception from HRESULT: 0x800401E3 (MK_E_UNAVAILABLE))
Can someone help me?
Thanks!
Matteo
Re: Read zenOn variables from Windows Service
Hello,<br><br>If you google that exception you will find some hints.<br>Like this: <a data-cke-saved-href="https://stackoverflow.com/questions/12828175/exception-from-hresult-0x800401e3-mk-e-unavailable-workarounds" href="https://stackoverflow.com/questions/12828175/exception-from-hresult-0x800401e3-mk-e-unavailable-workarounds">https://stackoverflow.com/questions/12828175/exception-from-hresult-0x800401e3-mk-e-unavailable-workarounds</a><br><br>My guesses:<br>- Runtime is not running<br>- Runtime is not accessable due to access rights<br>- Runtime does not have the Objectmodel active<br>- zenon API reference file is outdated<br><br>Also: In my code I refer to "zenOn.Application" and not "IApplication".<br>Not sure if that matters.<br><br>Hope that helps.<br><br>BR,<br>Georg
Re: Read zenOn variables from Windows Service
Hi Matteo,<br><br>When the zenon runtime is started as a service, it is also necessary for the console application to be started in the same session (session 0) within the same user context as the zenon runtime, in order to access the API. Windows, through something called session 0 isolation, prohibits applications in another (interactive) session to interact with applications or services in session 0. <br><br>Also Windows restricts inter process communication through the API not only to the same session but also to the user and the user elevation level. When you start the runtime as a regular user and a console application in the same user context but with elevation (e.g. because visual studio was started with elevation and debugging was started from studio), the interaction will fail.<br><br>Best regards,<br>Mark
Re: Read zenOn variables from Windows Service
Quote:
Originally Posted by
georgk
Hello,<br><br>If you google that exception you will find some hints.<br>Like this: <a data-cke-saved-href="https://stackoverflow.com/questions/12828175/exception-from-hresult-0x800401e3-mk-e-unavailable-workarounds" href="https://stackoverflow.com/questions/12828175/exception-from-hresult-0x800401e3-mk-e-unavailable-workarounds">https://stackoverflow.com/questions/12828175/exception-from-hresult-0x800401e3-mk-e-unavailable-workarounds</a><br><br>My guesses:<br>- Runtime is not running<br>- Runtime is not accessable due to access rights<br>- Runtime does not have the Objectmodel active<br>- zenon API reference file is outdated<br><br>Also: In my code I refer to "zenOn.Application" and not "IApplication".<br>Not sure if that matters.<br><br>Hope that helps.<br><br>BR,<br>Georg
<br><br>Hi Georg,<br><br>thanks for the reply.<br>I think that was an access rights problem.<br>I forced the service to run from the same account that started the zenOn runtime but it doesn't work.<br>I don't understand why.<br><br>Best regards,<br><br>Matteo
Re: Read zenOn variables from Windows Service
Quote:
Originally Posted by
markclemens
Hi Matteo,<br><br>When the zenon runtime is started as a service, it is also necessary for the console application to be started in the same session (session 0) within the same user context as the zenon runtime, in order to access the API. Windows, through something called session 0 isolation, prohibits applications in another (interactive) session to interact with applications or services in session 0. <br><br>Also Windows restricts inter process communication through the API not only to the same session but also to the user and the user elevation level. When you start the runtime as a regular user and a console application in the same user context but with elevation (e.g. because visual studio was started with elevation and debugging was started from studio), the interaction will fail.<br><br>Best regards,<br>Mark
<br><br>Hi Mark,<br><br>thanks for the reply.<br>I understand what you say but I think that is a access rights problem.<br>In my case the zenOn runtime doesn't start as a service. If I use a console application, it connects to zenOn and everything works correctly.<br>When I change it in a Windows service, even if I force the service to run with the same user who ran the zenOn Runtime, I have the same Exception.<br>I don't understand why.<br><br>Best regards,<br><br>Matteo<br>
<br>